CSS中的类名是否有最大字符数?
答案 0 :(得分:61)
.thereisnomaximumlengthforaclassnameincss {
maxlength: no;
}
祝你好运!
它没有最大长度。
答案 1 :(得分:37)
没有最大值。
基本上,名称可以以下划线(_),短划线( - )或字母(a-z)开头,然后紧跟一个字母或下划线,然后有任意数量的短划线,下划线,字母或数字:
-?[_a-zA-Z]+[_a-zA-Z0-9-]*
答案 2 :(得分:9)
不要忘记带宽。它似乎没有什么区别,但是一个带有30个长名称类的css文件可能会在大型网站上出现大的性能问题
答案 3 :(得分:2)
CSS 2.1的W3C架构 -
另外,我使用了他们的CSS验证器,它有一个非常长的类名......它通过了验证 -
答案 4 :(得分:2)
要添加其他人写的东西,只想添加if - 像我一样 - 你发现你有时候会结束疯狂的长名(因为你喜欢描述)然后值得记住选择器,这也促进风格重复使用并有助于保持易读性。
e.g。
h1 {
1.5em;
}
styledParagraph {
font-size: 1em;
}
/* Override the default font size if the styledParagraph element is inside an element with the class articlePage */
.articlePage .styledParagraph {
font-size: 1.5em;
}
/* Make all <h1> elements in .articlePage -> . styledParagraph larger than the default */
.articlePage .styledParagraph h1 {
font-size: 2em;
}
这得到了广泛支持(即使在MSIE 6中),它比类名更容易阅读。 articlePageStyleParagraphHeading 。
答案 5 :(得分:1)
与HTML中的ID名称上的this question类似。似乎没有“实际”限制。
我说保持它们尽可能短,同时仍然是描述性的 - 为什么甚至与疯狂的名字调情? :)