Are CSS selectors case-sensitive?(CSS 选择器区分大小写吗?)
问题描述
我最近更新了一个 CMS 网站,一个标签导航插件插入了以下标记:
I was recently updating a CMS site and a tab-navigation plugin had inserted the following markup:
<li id="News_tab">...
我的 CSS 选择器总是用小写字母编写,所以当我尝试使用 #news_tab
对其进行样式设置时,它不适用,但 #News_tab
有效.
I've always written my CSS selectors in lowercase so when I tried to style this with #news_tab
, it wouldn't apply, but #News_tab
worked.
这么多年过去了,我很惊讶我以前没有遇到过这种情况,所以我一直认为 CSS 是不区分大小写的.CSS 是否一直是区分大小写的,由于我一致的代码风格,我只是没有注意到?
After all these years I'm surprised that I haven't run into this before, so I've always been under the impression that CSS was case-insensitive. Has CSS always been case-sensitive and I just haven't noticed thanks to my consistent code style?
推荐答案
CSS 本身不区分大小写,但 HTML 中的选择器(class 和 id)区分大小写:
CSS itself is case insensitive, but selectors from HTML (class and id) are case sensitive:
关于区分大小写的 CSS 建议
HTML 推荐,id 属性(注意[CS])
这篇关于CSS 选择器区分大小写吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!