在这段代码中:
我想在鼠标悬停时改变颜色。
可能的答案:
更难的版本:
<div id="Container">
<span class='first'>First</span>
<span class='second'>Second</span>
<span class='third'>Third</span>
</div>
我想在鼠标悬停时改变颜色。
- 如果 (.first:hover) 那么 .first { color: red; }
- 如果 (.second:hover) 那么 .first, .second { color: red; }
- 如果 (.third:hover) 那么 .first, .second, .third { color: red; }
可能的答案:
- @panther 的回答
更难的版本:
<div id="Container">
<span class='first' style='color: red'>First</span>
<span class='second' style='color: green'>Second</span>
<span class='third' style='color: blue'>Third</span>
</div>
- 如果鼠标悬停在
.first
上,则将.first
的颜色设置为粉色。 - 如果鼠标悬停在
.second
上,则将.first
和.second
的颜色都设置为粉色。 - 如果鼠标悬停在
.third
上,则将.first
、.second
和.third
的颜色都设置为粉色。
答案:
- @Armfoot的回答似乎很好 :)
@at-root
属性完成某些操作,所有元素的父元素都具有相同的类... 我还在考虑中。 +1 鼓励挑战 :P - Armfootspan
提供了你的第二个问题的解决方案。 - pavel