[英]css specificty id vs attribute
Having trouble understanding one particular specificity instance, maybe I'm over thinking it. 难以理解一个特定的特异性实例,也许我在思考它。
For example: 例如:
.class#id vs .class #id In the first case, the html would be something like right. .class #id vs .class #id在第一种情况下,html会是正确的。 So to me this makes me think it's acting like an attribute.
所以对我来说这让我觉得它就像一个属性。 Does that change the specificity?
这会改变特异性吗?
Edit: In other words I'm asking .class#id : specificity=1-1-0 .class #id: specificity=1-1-0 编辑:换句话说,我问.class #id:specificity = 1-1-0 .class #id:specificity = 1-1-0
Likewise, for instance .class[id="id"] attribute or id? 同样,例如.class [id =“id”]属性或id?
In the first case: .class#id
matches 在第一种情况下:
.class#id
匹配
<div class="class" id="id"><div> <!-- matches this div -->
But this .class #id
matches 但这个
.class #id
匹配
<div class="class">
<div id="id"> <!-- matches this div -->
</div>
Having no spaces in a CSS selector means they will apply to the same element. CSS选择器中没有空格意味着它们将应用于同一元素。 Spaces will imply child elements.
空间将暗示儿童元素。
Specificity 特异性
In regards to your last case .class[id=id]
is almost exactly the same as the first case: .class#id
is "more specific" than .class[id=id]
since attr
's in CSS have lower precedence than id
's. 关于你的最后一个案例
.class[id=id]
几乎与第一种情况完全相同: .class#id
比.class[id=id]
“更具体”,因为CSS中的attr
优先级高于id
的。
For an excellent read on CSS specificity look here . 有关CSS特性的优秀阅读,请查看此处 。
.class#id{ background-color:red} /*specificity 0110*/ .class[id="id"]{ background-color:green} /*specificity 0020*/
<div class="class" id="id">lorem</div>
for .class#id, Specificity is
对于.class#id,特异性是
for .class[id="id"], Specificity is
对于.class [id =“id”],特异性是
Reference: Specificity Calculator 参考: 特异性计算器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.