为什么是
一个元素,而不是一个实体?
可能的重复:
为什么
HTML 元素而不是 HTML 实体?
为什么 HTML 中的换行符是元素
而不是实体,例如 &br;
?在许多方面,它似乎不太适合作为一个元素(例如,与普通 HTML 元素具有不同的节点类型属性,其功能类似于
)。
Possible Duplicate:
Why is <br> an HTML element rather than an HTML entity?
Why is a line break in HTML an element <br>
instead of an entity, such as &br;
? In many ways it seems a bad fit to be an element (e.g. has a different node type attribute to normal HTML elements, is similar to
in what it does).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HTML 中的空白将呈现为一个字符空间,无论空白的数量是多少。这有助于标记作者身份而不影响标记呈现。
>不是显示字符,而是格式影响内容含义时的格式说明符。 HTML 5 规范规定,它“必须仅用于实际属于内容一部分的换行符,例如诗歌或地址中的换行符”。
Whitespace in HTML is rendered as a one character space regardless of the amount of whitespace. This assists in markup authorship without impacting the markup rendering.
<br/> is not a display character, but a formatting specifier for when the format affects the content's meaning. The HTML 5 spec states that it "must be used only for line breaks that are actually part of the content, as in poems or addresses."
来自规范*
因此它清楚地表明可以将换行符设置为其他样式,从而证明它不是一个实体。它确实让我认为应该有两种添加换行符的方法 - 作为实体
&br;
或标签
,从而给作者提供了换行符是否可设置样式的灵活性。如果你问我的话,上面的说法——将诗歌和地址中换行符的使用等同起来——有点笼统。*不确定它是否是规范,但它肯定是规范
From the spec*
So it states clearly that it is ok to style a line break as something else, thus justifying why it's not an entity. It does make me think that there should be two ways of adding a line break - as an entity
&br;
or a tag<br>
, thus giving the author flexibility over whether the line break is stylable or not. The statement above - equating use of line breaks in poems and addresses - is a bit of a broad brush if you ask me.*Not sure if it's the spec, but it's certainly a spec