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 选择器区分大小写吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CSS 选择器区分大小写吗?
基础教程推荐
- Bokeh Div文本对齐 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
