CSS 选择器区分大小写吗?
我最近更新了一个 CMS 网站,一个选项卡导航插件插入了以下标记:
<li id="News_tab">...
我总是用小写形式编写 CSS 选择器,因此当我尝试使用 #news_tab
对其进行样式设置时,它不会不适用,但 #News_tab
有效。
这么多年过去了,我很惊讶我以前没有遇到过这种情况,所以我一直认为 CSS 不区分大小写。 CSS 是否始终区分大小写,只是由于我一致的代码风格而没有注意到?
I was recently updating a CMS site and a tab-navigation plugin had inserted the following markup:
<li id="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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
http://www.w3.org/TR/CSS2/syndata.html
(来自文档网站)。
选择器的后续:
http://www.w3.org/TR/CSS2/selector .html
http://www.w3.org/TR/CSS2/syndata.html
From the docs website.
Follow-up for selectors:
http://www.w3.org/TR/CSS2/selector.html
CSS 本身不区分大小写,但 HTML 选择器(类和 id)区分大小写:
关于区分大小写的 CSS 建议
HTML 推荐,id 属性 (请注意 [CS])
CSS itself is case insensitive, but selectors from HTML (class and id) are case sensitive:
CSS recommendation on case sensitivity
HTML recommendation, id attribute (note the [CS])
CSS4(CSS 选择器级别 4) 增加了支持用于不区分大小写的匹配(仅限 ASCII)。
input[value='search' i]
这是末尾的“i”,可以解决这个问题...
检查我的其他答案了解哪些浏览器支持此功能的详细信息。
CSS4 (CSS Selector Level 4) adds support for case-insensitive match (ASCII only).
input[value='search' i]
It's the "i" at the end which would do the trick...
Check my other answer for details which browser supports this.
类和 ID 属性区分大小写。
Class and ID attributes are case sensitive.