【发布时间】:2019-05-21 23:22:22
【问题描述】:
据我所知,从question 来看,css 选择器不区分大小写,但 HTML 属性(类名)区分大小写,因此恕我直言,.example 应该被 .Examplecss 选择器覆盖,但这不会发生。 <div class="example">color 仍然是红色而不是蓝色,因为 css 选择器不区分大小写。
.example {
color: red;
}
.Example {
color: blue;
}
<div class="example">
example
</div>
【问题讨论】:
-
上面写着
But HTML class names are case-sensitive (see the attribute definition), and that's causing a mismatch in your second example. This has not changed in HTML5.1所以.. -
@golddragon007 他已经在问题中包含了该链接..
-
从链接的问题中,接受的答案是
CSS selectors are generally case-insensitive... But HTML class names are case-sensitive。正如您在我的代码中看到的那样,html 类名称class="example"是小写的,但 css 有 2 个类.example和.Example应该选择div.example"因此它的颜色应该是蓝色,因为.Example覆盖了由.example -
正如我在回答中已经说过的,@treyBake 引号,HTML 类名区分大小写是您的第二条规则不匹配的原因 - 因为“示例”和“示例”不一样 -因此没有什么可以覆盖的。
-
class和id区分大小写。tags不是。所以 css 中的p或P将选择<p>html 元素。通过说HTML class names are case-sensitive暗示当您尝试在 CSS 中选择它们时就是这种情况。并不是说你不能使用ExAmPle作为类名(虽然不推荐)
标签: html css css-selectors