问题描述
我随时随地阅读CSS不区分大小写,但我有这个选择器
I keep reading everywhere that CSS is not case sensitive, but I have this selector
.holiday-type.Selfcatering
当我在我的HTML中使用时,像这样,被拾起
which when I use in my HTML, like this, gets picked up
<div class="holiday-type Selfcatering">
如果我像这样更改上述选择器
If I change the above selector like this
.holiday-type.SelfCatering
推荐答案
CSS选择器通常不区分大小写;这包括类和ID选择器。
CSS selectors are generally case-insensitive; this includes class and ID selectors.
但(请参阅属性定义),这会导致您的第二个示例不匹配。 中没有更改。
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.
这是因为选择器的区分大小写功能:
This is because the case-sensitivity of selectors is dependent on what the document language says:
因此,给定一个文档语言元素名称,属性名称和属性值在选择器中的区分大小写。具有 Selfcatering
类但没有 SelfCatering
类的HTML元素,选择器 .Selfcatering
和
[class〜=Selfcatering]
将匹配它,而选择器 .SelfCatering
[class〜=SelfCatering]
不会。
So, given an HTML element with a Selfcatering
class but without a SelfCatering
class, the selectors .Selfcatering
and [class~="Selfcatering"]
will match it, while the selectors .SelfCatering
and [class~="SelfCatering"]
would not.
这篇关于CSS选择器中的类名是否区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!