html - 在 HTML 元素上有多个单独的类属性是否有效?

标签 html validation

在 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/

相关文章:

php - 内联 css 工作但外部和内部 css 在 index.php 中不起作用

html - 带有 css 的居中框 - 对齐错误

html - 如何避免重叠的 HTML 标签来突出显示文本

javascript - 避免在按钮单击时出现多个克隆或重复的 div,并在最后一个克隆的 div 之后插入一次

asp.net-mvc - 禁用某些字段的验证

验证用户名时的 PHP 错误

java - 如何进一步验证 Java 中的 jTextBox 以允许点和逗号?

javascript - 如何在angularjs中创建搜索过滤器和文本突出显示

c# - 用不同的文化处理验证的最佳方法是什么

php - Codeigniter 的正则表达式匹配