基于多个类选择元素 [英] Select element based on multiple classes
问题描述
我有一个样式规则,当它有两种样式时,我想应用于标记。有没有任何方式来执行这个没有JavaScript?换句话说:
I have a style rule I want to apply to a tag when it has two styles. Is there any way to perform this without JavaScript? In other words:
<li class='left ui-class-selector'>
我想只应用我的样式规则 c> li 同时应用了 .left
和 .ui-class-selector
I want to apply my style rule only if the li
has both .left
and .ui-class-selector
classes applied.
推荐答案
你的意思是两个类? 链选择器(它们之间没有空格):
You mean two classes? "Chain" the selectors (no spaces between them):
.class1.class2 {
/* style here */
}
这将选择 class1 $
This selects all elements with class1
that also have class2
.
在您的情况下:
li.left.ui-class-selector {
}
官方文档: CSS2类选择器。
由于akamike 指出此方法的问题Internet Explorer 6,您可能想阅读:在IE6 CSS中使用双类?
As akamike points out a problem with this method in Internet Explorer 6 you might want to read this: Use double classes in IE6 CSS?
这篇关于基于多个类选择元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!