在 HTML 元素中使用多个单独的类属性是否有效?
像这样:
<div class="first-class" class="second-class">
</div>
我知道可以将多个类名放在一个类属性中,我只是想知道是否允许以其他方式进行,还是绝对禁止?
最佳答案
不可以,您必须只有一个类属性。多个类之间用空格分隔。
<div class="first-class second-class"></div>
以下是 HTML 标准规范的引用资料:
There must never be two or more attributes on the same start tag whose names are an ASCII case-insensitive match for each other.
https://html.spec.whatwg.org/multipage/syntax.html#syntax-attributes
This error occurs if the parser encounters an attribute in a tag that already has an attribute with the same name. The parser ignores all such duplicate occurrences of the attribute.
https://html.spec.whatwg.org/multipage/parsing.html#parse-error-duplicate-attribute
关于html - 在 HTML 元素上有多个单独的类属性是否有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9280395/