gpt4 book ai didi

html - 空类属性是有效的 HTML 吗?

转载 作者:技术小花猫 更新时间:2023-10-29 12:25:25 24 4
gpt4 key购买 nike

是一个空的 class 属性,具有以下格式的有效 HTML:

<p class="">something</p>
<p class>something</p>

我找到了 this question这很相似,但特别询问自定义数据属性。

最佳答案

在查看其他答案中提到的规范后,我找到了实际回答所提出问题的部分。

<p class>不允许

specification on attributes关于空属性语法的第 3.2.3.1 节说明如下:

An empty attribute is one where the value has been omitted. This is a syntactic shorthand for specifying the attribute with an empty value, and is commonly used for boolean attributes. This syntax may be used in the HTML syntax, but not in the XHTML syntax.

(...)

This syntax is permitted only for boolean attributes.

看到 description of the class attribute (显然)没有提到它是一个 bool 属性,不允许省略该值。

<p class=""> 允许的

来自 the section on class我们了解到:

Every HTML element may have a class attribute specified.

The attribute, if specified, must have a value that is a set of space-separated tokens representing the various classes that the element belongs to.

并且来自 space-seperated tokens 的定义:

A set of space-separated tokens is a string containing zero or more words (known as tokens) separated by one or more space characters, where words consist of any string of one or more characters, none of which are space characters.

我们可以得出结论,属性值实际上可以为空(即包含零个标记)。

关于html - 空类属性是有效的 HTML 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30748847/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com