空类属性是否有效HTML? [英] Is an empty class attribute valid HTML?

查看:98
本文介绍了空类属性是否有效HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

属于空的属性是否为以下格式的有效HTML:

Is an empty class attribute valid HTML in the following formats:

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

我发现这个问题类似,但具体询问自定义数据属性。

I found this question which is similar, but asks specifically about custom data attributes.

推荐答案

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

After looking at the specifications referred to in the other answers, I have found the sections that actually do answer the raised question.

属性规范第3.2.3.1节空属性语法声明如下:

The specification on attributes section 3.2.3.1 on Empty Attribute Syntax states the following:


空属性是省略值的属性。这是用于指定具有空值的属性的语法简写,通常用于布尔属性。此语法可以在HTML语法中使用,但不能在XHTML语法中使用。

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.

看到类属性的描述(显然)没有提到它是一个布尔属性,不允许省略该值。

Seeing that the description of the class attribute (obviously) does not mention it being a boolean attribute, omitting the value is not permitted.

课程部分我们了解到:


每个HTML元素都可以指定一个类属性。

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.

并且来自空格分隔的标记


一组空格分隔的标记是一个包含的字符串由一个或多个空格字符分隔的零个或多个单词(称为标记),其中单词由一个或多个字符的任意字符串组成,其中没有一个是空格字符。

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.

我们可以得出结论,属性值实际上可以是空的(即包含零令牌)。

we can conclude that the attribute value can in fact be empty (i.e. containing zero tokens).

这篇关于空类属性是否有效HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆