我还想将“three”的背景颜色更改为“lightblue”,但仅当页面上存在“one current”类组合时。注意:“three”不能获得其他类。我知道,您可以使用JavaScript来完成此操作,但是否也有本地CSS解决方案?
这是我的示例:
这是我的示例:
<!DOCTYPE html>
<html>
<head>
<style>
.one.current {background-color: lightblue;}
</style>
</head>
<body>
<header>
<p class="one current">The first paragraph.</p>
</header>
<main>
<p class="two">The second paragraph.</p>
<p class="three">The third paragraph.</p>
<p class="four">The fourth paragraph.</p>
</main>
</body>
</html>
one current
应用于它们的前任吗?在这种情况下,是<body>
吗? - Ramon Balthazarheader
元素,这样.one.current + main > .three
就可以工作了。 - Ilya Streltsyn