CSS:HTML元素可以有多少类的限制? [英] CSS: Is there a limit on how many classes an HTML element can have?
问题描述
CSS允许HTML元素包含多个类:
CSS allows an HTML element to have multiple classes:
<div class="cat persian happy big"> Nibbles </div>
但是每个项目允许有多少个
But is there a limit on how many classes are allowed per item?
推荐答案
您只受(X)HTML属性值的最大长度的限制,此答案。
You're only limited by the maximum length of an (X)HTML attribute's value, something covered well by this answer.
浏览器通常是非常原谅标准违规,因此个别浏览器可能允许更长的类属性。此外,您可能可以通过JavaScript向DOM元素添加几乎无限数量的类,受到浏览器可用内存量的限制。
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.
对于所有意图和目的,没有限制。我假设你要求好奇心;不用说,如果你真的担心达到这个极限,你做了一些非常错误。
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.
这篇关于CSS:HTML元素可以有多少类的限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!