是否可以为元素定义CSS样式,该样式仅在匹配的元素包含特定元素(作为直接子项)时应用?
我认为用一个例子来解释这一点最好。
注意:我正在尝试样式化父元素,这取决于它包含的子元素。
<style>
/* note this is invalid syntax. I'm using the non-existing
":containing" pseudo-class to show what I want to achieve. */
div:containing div.a { border: solid 3px red; }
div:containing div.b { border: solid 3px blue; }
</style>
<!-- the following div should have a red border because
if contains a div with class="a" -->
<div>
<div class="a"></div>
</div>
<!-- the following div should have a blue border -->
<div>
<div class="b"></div>
</div>
CSSNote2CSS:我知道我可以使用javascript来实现这一点,但我只是想知道是否可以使用一些(对我来说)未知的特性。
https://stackoverflow.com/questions/2326499
复制相似问题