CSS:一个 HTML 元素可以有多少个类有限制吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4354921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CSS: Is there a limit on how many classes an HTML element can have?
提问by Tony the Pony
CSS allows an HTML element to have multiple classes:
CSS 允许一个 HTML 元素有多个类:
<div class="cat persian happy big"> Nibbles </div>
But is there a limit on how manyclasses are allowed per item?
但有一个限制多少班每件被允许?
采纳答案by meagar
You're only limited by the maximum length of an (X)HTML attribute's value, something covered well by this answer.
您仅受 (X)HTML 属性值的最大长度限制,此答案很好地涵盖了这一点。
Browsers are often very forgiving of standards violations, so individual browsers may allow much longer class attributes. Additionally you are likely able to add a practically infinite number of classes to a DOM element via JavaScript, limited by the amount of memory available to the browser.
浏览器通常对违反标准非常宽容,因此个别浏览器可能允许更长的类属性。此外,您可能能够通过 JavaScript 向 DOM 元素添加几乎无限数量的类,但受浏览器可用内存量的限制。
For all intents and purposes, there is no limit. I'm assuming you're asking out of curiosity; it goes without saying that if you're seriously worried about hitting this limit, you've done something very wrong.
对于所有意图和目的,没有限制。我假设你是出于好奇而问的;不用说,如果您真的很担心达到这个限制,那您就做错了。
回答by zubinmehta
No. I don't think, I have ever come across any such limit/
不。我不认为,我曾经遇到过任何这样的限制/
EDIT: Sorry for the casual remark.
According to the specifications, there isn't any limit but someone has tried to reach this limit and it seems the limit for Opera, Safari supported well over 4000 classes, and Firefox at least 2000 classes!
Source: http://kilianvalkhof.com/2008/css-xhtml/maximum-number-of-supported-classes-per-element/
编辑:对不起,随意评论。
根据规范,没有任何限制,但有人试图达到这个限制,似乎 Opera 的限制,Safari 支持超过 4000 个类,而 Firefox 至少支持 2000 个类!
来源:http: //kilianvalkhof.com/2008/css-xhtml/maximum-number-of-supported-classes-per-element/
回答by joemccann
There is no technical limit (barring the amount of memory the browser may be consuming), but one should heavily consider having loads of classes on any element as the browser will have to parse all the classes, apply those styles and render the page.
没有技术限制(除非浏览器可能消耗的内存量),但应该认真考虑在任何元素上加载类,因为浏览器必须解析所有类,应用这些样式并呈现页面。
Also, if you need to search the DOM for elements of a particular class and elements contain loads of classes, you may likely see a performance issue if the JavaScript interpreter has to parse loads of classes.
此外,如果您需要在 DOM 中搜索特定类的元素并且元素包含大量类,并且 JavaScript 解释器必须解析大量类,则您可能会看到性能问题。
回答by kobe
No ,
不 ,
There won't be any limit.
不会有任何限制。