为什么是
一个元素,而不是一个实体?

发布于 2025-01-02 08:29:41 字数 361 浏览 2 评论 0原文

可能的重复:
为什么
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彻夜缠绵 2025-01-09 08:29:41

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."

宁愿没拥抱 2025-01-09 08:29:41

来自规范*

br 元素代表换行符。

虽然换行符在视觉媒体中通常表示为
将后续文本物理移动到新行、样式表或用户
代理同样有理由导致换行被渲染
以不同的方式,例如作为绿点,或作为额外的
间距。

br 元素只能用于实际组成部分的换行符
内容,如诗歌或地址。

因此它清楚地表明可以将换行符设置为其他样式,从而证明它不是一个实体。它确实让我认为应该有两种添加换行符的方法 - 作为实体 &br; 或标签
,从而给作者提供了换行符是否可设置样式的灵活性。如果你问我的话,上面的说法——将诗歌和地址中换行符的使用等同起来——有点笼统。

*不确定它是否是规范,但它肯定是规范

From the spec*

The br element represents a line break.

While line breaks are usually represented in visual media by
physically moving subsequent text to a new line, a style sheet or user
agent would be equally justified in causing line breaks to be rendered
in a different manner, for instance as green dots, or as extra
spacing.

br elements must be used only for line breaks that are actually part
of the content, as in poems or addresses.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文