< [ ] \ { } | ` #-6ren">
gpt4 book ai didi

css - 哪些字符在 CSS 类名/选择器中有效?

转载 作者:行者123 更新时间:2023-11-28 03:32:58 26 4
gpt4 key购买 nike

CSS 类选择器中允许使用哪些字符/符号?

我知道以下字符无效,但哪些字符有效

~ ! @ $ % ^ & * ( ) + = , . / ' ; : " ? > < [ ] \ { } | ` #

最佳答案

您可以直接在CSS grammar查询.

基本上1,名称必须以下划线 (_)、连字符 (-) 开头, 或一个字母 (az),后跟任意数量的连字符、下划线、字母或数字。有一个问题:如果第一个字符是连字符,第二个字符必须2 是字母或下划线,并且名称必须至少有 2 个字符长。

-?[_a-zA-Z]+[_a-zA-Z0-9-]*

简而言之,前面的规则转换为以下规则,摘自 W3C specification :

In CSS, identifiers (including element names, classes, and IDs inselectors) can contain only the characters [a-z0-9] and ISO 10646characters U+00A0 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 10646character as a numeric code (see next item). For instance, theidentifier "B&W?" may be written as "B&W?" or "B\26 W\3F".

以连字符或下划线开头的标识符通常保留给特定于浏览器的扩展,如 -moz-opacity

1 由于包含转义的 Unicode 字符(没有人真正使用),这一切都变得更加复杂。

2 请注意,根据我链接的语法,以两个 连字符开头的规则(例如,--indent1)是无效的.但是,我很确定我已经在实践中看到了这一点。

关于css - 哪些字符在 CSS 类名/选择器中有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44633791/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com