如何在CSS选择器中结合类和ID? [英] How to combine class and ID in CSS selector?
本文介绍了如何在CSS选择器中结合类和ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有以下div:
<div class="sectionA" id="content">
Lorem Ipsum...
</div>
有一种方法来定义一个风格,表达的想法A div with id ='content'
AND class ='myClass'
?
Is there a way to define a style that expresses the idea "A div with id='content'
AND class='myClass'
"?
<div class="content-sectionA">
Lorem Ipsum...
</div>
或
<div id="content-sectionA">
Lorem Ipsum...
</div>
推荐答案
在您的样式表中:
div#content.myClass
Edit:这些也可能有帮助:
These might help, too:
div#content.myClass.aSecondClass.aThirdClass /* Won't work in IE6, but valid */
div.firstClass.secondClass /* ditto */
根据您的示例:
div#content.sectionA
编辑,4年后 strong>:由于这是超级旧的,并且人们不断地找到它:不要使用tagNames您的选择器。 #content.myClass
比 div#content.myClass
更快,因为tagName添加了一个过滤步骤需要。 只有在必须的地方才在选择器中使用tagNames!
Edit, 4 years later: Since this is super old and people keep finding it: don't use the tagNames in your selectors. #content.myClass
is faster than div#content.myClass
because the tagName adds a filtering step that you don't need. Use tagNames in selectors only where you must!
这篇关于如何在CSS选择器中结合类和ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文