正如你可以看到下面,div#test
是仅适用于使用ID test
div的选择。 #test
将选择编号为test
的每个元素。
但是,既然你不应该多次使用一个id,这应该不成问题。 div#test
只会减慢DOM中的匹配,所以你不应该使用它。
要明确:如果你链接元素和ID,你更具体。这意味着,这些规格将始终覆盖较不具体的规格。
div#test{color:green}
#test{color:red}
颜色会变成绿色。
如果您的意思是div #test
,那是通过DOM树链接。
div#test{ float:right}
#test{color:green}
div #test{margin-left:60px}
<html>
<head></head>
<body>
<div>
<span>Some stuff here..</span>
</div>
<div id="test">
<span>This is my data</span>
</div>
<span id="test">no data</span>
<div>
<span id="test">heres data</span>
</div>
<div>
<p>
<span id="test">heres data aswell</span>
</p>
</div>
</body>
</html>
ID与#,其中id是一个唯一的标识符来表示。你可以使用id做一个css选择器。 –
我会建议你阅读选择器和它们的特殊性。 – evolutionxbox