为什么他们不赞成使用预格式化文本的宽度属性?

发布于 2024-09-12 20:43:02 字数 293 浏览 3 评论 0原文

width 属性定义了每行的最大字符长度,在 HTML 4.01 中已被弃用,并且在当前的 HTML5 草案中我不再看到它。我在 W3C 的 HTML 工作组的邮件列表中找不到其背后的原因(也许我搜索错误),尽管 4.01 的规范表示并非所有客户端都支持它。

  1. 一种可能的答案是:对预先格式化的文本进行换行是没有意义的。这是真的吗?
  2. 如果我仍然希望它在 30 个字符后换行。除了脚本之外,我如何实现这一目标?

The width attribute for <pre>, which defines maximum character length per line, was deprecated in HTML 4.01, and I no longer see it in current draft of HTML5. I couldn't find the reason behind it in the mailing lists of W3C's WG for HTML (maybe I searched wrong), although the specs for 4.01 said it was not supported in all clients.

  1. One possible answer: it makes no sense to wrap preformatted texts. Is this true?
  2. In case I still want it to wrap after for example 30 characters. Besides scripting, how do I achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

醉生梦死 2024-09-19 20:43:02

不推荐使用表现性定义属性,取而代之的是 CSS。您不应依赖 sizewidthheight 属性,而应在进行标记时关注语义。 (尽管一个例外可能是用于预加载渲染目的的 img 元素)。

Presentational defining attributes were deprecated in favor of CSS. You should not rely on size, width, height attributes but instead focus on semantics when doing the markup. ( Though one exception is probably the img element for preload rendering purposes ).

一向肩并 2024-09-19 20:43:02

不是一个结论性的答案,但看起来它已被弃用,因为它从未得到适当的支持(并且因为它是一个演示问题,因此实际上不是 HTML 应该包含的内容)......

看看它的提及 在 HTML 4.01 规范中,它提到它没有得到广泛支持,并且它用于“选择适当的字体大小或适当缩进”——这听起来与“定义每行的字符数”相去甚远。

这些旧的 HTML 元素/属性消失的正常原因是它们比 HTML 更适合 CSS——HTML 应该只是内容,而不是表示。

Not a conclusive answer, but it looks like it was deprecated because it was never properly supported (and because it's a presentational concern, and therefore not really something HTML should contain)....

Take a look at it's mention in the HTML 4.01 spec, it mentions it's not widely supported and that it's used to "select an appropriate font size or indent appropriately"--which sounds pretty far off from "defines the number of characters per row".

The normal reason for these old HTML elements/attributes to go away is that they're better aligned with CSS than HTML--HTML is supposed to be just content, not presentation.

蘸点软妹酱 2024-09-19 20:43:02

嗯,首先,您希望将 contentpresentation 分开,在

 的情况下,宽度纯粹是演示性的。此外,正如您所指出的,包装预先格式化的文本没有什么意义。如果你真的想的话,你可以在 CSS 中做到这一点:

pre {
    width: 30em;
    white-space: pre-wrap;
}

Well, for one, you'd want to separate content from presentation , and in the case of <pre>, the width is purely presentational. Furthermore, it makes little sense to wrap preformatted text, as you point out. You can do that in CSS if you really want to:

pre {
    width: 30em;
    white-space: pre-wrap;
}
秋凉 2024-09-19 20:43:02

HTML 用于定义文档的结构,而不是用于设计文档的样式。还有一个类似的 CSS 属性,称为 width

HTML is for defining the structure of a document, not for styling of it. And there is a similar CSS property called width.

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