我不敢相信在我编写 CSS 的很长一段时间里,我从来没有这样做过,但这让我很难过。
我有span.item-name
并且我想仅在此元素具有另一个类(可以是任何类)时添加一些特定样式。
我试过了span.item-name.*
,但它不起作用。这是可能的,我有哪些选择?
您可以使用属性选择器。(参见:https : //www.w3.org/wiki/CSS/Selectors#Attribute_Selector)示例:
body>.item-name:before, b {
content:'Class name is: 'attr(class)'. ';
color:purple
}
p[class*="item-name"][class*=" "]:before {
color:green;
}
p[class^="item-name"][class*=" "]:before {
color:red;
}
<p class="item-name"> The basic class</p>
<p class="item-name another-class"> the basic class at first and then any other</p>
<p class="another-class item-name any-more-class"> more than one class including <b>item-name</b> at any position</p>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句