我可以在CSS类名称中使用camel-case [英] Can I use camel-case in CSS class names

查看:115
本文介绍了我可以在CSS类名称中使用camel-case的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想命名一个CSS类,并调用它imgSuper。我可以在CSS类中使用camel-casing吗?

I want to name a CSS class and call it imgSuper. Can I use camel-casing in CSS classes?

推荐答案

技术上是有风险的,因为CSS语法最不区分大小写,在某些浏览器中,在某些条件下,类名称被视为区分大小写,因为规范没有规定浏览器在将CSS规则与HTML类名匹配时如何处理case。

Technically yes, but it's risky because while CSS syntax is mostly case-insensitive, in some browsers under certain conditions, class names are treated as case-sensitive, as the spec does not specify how browsers should handle case when matching CSS rules to HTML class names.

规范 section 4.1.3


所有CSS语法在ASCII范围内不区分大小写...

All CSS syntax is case-insensitive within the ASCII range...

在CSS中,标识符(包括选择器中的元素名称,类和ID) [a-zA-Z0-9]和ISO 10646字符U + 00A1和更高,加连字符( - )和下划线(_);他们不能以数字开头,或者连字符后跟数字。标识符还可以包含转义字符和任何ISO 10646字符作为数字代码(见下一项)。例如,标识符B& W可以写为B \& W \?或B \26 W \3F。

In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A1 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, or a hyphen followed by a digit. Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code (see next item). For instance, the identifier "B&W?" may be written as "B\&W\?" or "B\26 W\3F".

... HTML属性id和class的值的区分大小写名称和URI超出了本规范的范围。

...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.

不要学习敏感的浏览器和条件,你只是意识到最好的方法是最兼容:在给定的CSS类的所有代码中使用相同的情况,并且不创建两个或更多的CSS类名称只有在情况不同。

Rather than learn the browsers and conditions where case is sensitive, it's best that you just realize that the best approach is the most compatible: use the same case in all code for a given CSS class, and don't create two or more CSS class names that differ only in case.

这篇关于我可以在CSS类名称中使用camel-case的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆