html - [class$ =""] 和 [id* =""] 有什么特殊性?

标签 html css css-selectors css-specificity

[class$=" "]
[class*=" "]
[class^=" "]

以上所有内容(以及 ID 等效项)似乎都不遵循标准的 CSS 特异性权重规则。

我制作了一个 Codepen 来展示它们有多么古怪和矛盾。 http://codepen.io/mildrenben/pen/myYLmG

标记

<div id="wrap">
  <div class="container">
    <p> #idName is more specific than [id*="idName"]. But .className and [class*="className"] seem to be the same specificty.</p>
  </div>
</div>

CSS

#wrap {
  border: solid 5px green;
}

[id*="wrap"] {
  border: solid 5px red;
}

.container {
  background: red;
}

[class*="container"] {
  background: yellow;
}

p {
  font-family: sans-serif;
  padding: 6px;
}

谁能澄清一下这些选择器的特异性权重?

谢谢

最佳答案

#idName is more specific than [id*="idName"]. But .className and [class*="className"] seem to be the same specificty.

是的。那就是the spec says they should be .

count the number of ID selectors in the selector (= a)

count the number of class selectors, attributes selectors, and pseudo-classes in the selector (= b)

您有一个 id 选择器、两个属性选择器、一个类选择器和一个类型选择器。

关于html - [class$ =""] 和 [id* =""] 有什么特殊性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29557306/

相关文章:

html - 仅在 Bootstrap “导航栏菜单”上居中特定文本/按钮

javascript - 测试/导航其他网站的最佳语言

c# - 在后端更改 CSS

java - org.openqa.selenium.TimeoutException : Expected condition failed: waiting for visibility of element located by By. xpath:

css - 是否有 CSS 父级选择器?

python - Beautifulsoup 显示重复项

html - Bootstrap + 带有扩展预览的缩略图网格

css - 选择 ElementA 内不在 Element 内的每个元素,其中 Element 在 ElementS 内

ios - 用于 iPhone 的 HTML 文本链接向多个号码发送短信

javascript - reactjs中如何改变tooltip容器的宽度?