html - 如果 CSS 选择器不区分大小写,那么为什么不覆盖样式?

标签 html css css-selectors

<分区>

从这里question ,据我所知,css 选择器不区分大小写,但 HTML 属性(类名)区分大小写,因此恕我直言,.example应该被 .Example 覆盖css 选择器,但这不会发生。 <div class="example">颜色仍然是红色而不是我认为的蓝色,因为 css 选择器不区分大小写。

.example {
  color: red;
}

.Example {
  color: blue;
}
<div class="example">
  example
</div>

最佳答案

你完全正确! CSS 实际上主要是不区分大小写的。

但是 HTML 4.01 定义类名和 ID 名区分大小写,这在 HTML5 中没有改变。

All CSS syntax is case-insensitive within the ASCII range (i.e., [a-z] and [A-Z] are equivalent), except for parts that are not under the control of CSS. For example, the case-sensitivity of values of the HTML attributes "id" and "class", of font names, and of URIs lies outside the scope of this specification.

Source

关于html - 如果 CSS 选择器不区分大小写,那么为什么不覆盖样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53885595/

上一篇:css - 在元素符号后对齐 <li> 中的文本

下一篇:html - CSS 宽度属性无法正常工作

相关文章:

html - 将文本置于横幅中间?

jquery - 我希望同一页面上的两个 Flexslider 以不同的速度运行

php - 我创建了一个 CSS 切换器,但我只需要更改 body 类为 ="red"的元素

html - 列表项在 IE 和 Chrome 上无明显原因上移

javascript - 获取 data-* 属性的值,而不知道 "data-"之后的内容

css - Wordpress CSS 中的事件子菜单

html - 父 div 移至底部,因为我指定了子 div 边距

html - 如何让我的 css 仅应用于一个页面而不是所有页面

html - 为什么对 html 表单使用有序列表来提高可访问性?

css - 如何避免在 CSS 中重新定义父元素类