b, i, u, s标签:我们应该使用CSS吗?

huangapple go评论60阅读模式
英文:

b, i, u, s tags: should we use CSS instead?

问题

<b>, <i>, <u><s>标签纯粹是“视觉”效果,没有传达任何语义意义。

I've <em>already</em> told you <em>four</em> times
that I do <em>not</em> like <i>The Lord of the Rings</i> movie.
Please, stop.

尽管如此,这些标签并没有被正式弃用,甚至在MDN Web Docs和W3Schools上也没有被标记为“不推荐使用”。

例如,这里是来自W3Schools的一则说明:

根据HTML5规范,<b>标签应该作为最后的选择,当没有其他标签更合适时才使用。规范指出,标题应该用<h1><h6>标签表示,强调文本应该用<em>标签表示,重要文本应该用<strong>标签表示,标记/高亮文本应该用<mark>标签表示。

您还可以使用以下CSS来设置粗体文本:"font-weight: bold;"

正如您所看到的,尽管W3Schools的文章对使用<b>标签有些不鼓励,但它并没有解释为什么<b>标签没有被弃用。

因此,我来回答您的问题:

  • 为什么这些标签没有被弃用?
  • 我们是否应该用CSS替换它们,以更好地遵循“将内容与表现分离”的理念?
  • 换句话说,CSS的font-weight: bold是否真的是<b>的1对1替代?(对于<i><u><s>是否也一样?)

Is there anything else you would like to know?

英文:

<b>, <i>, <u>, and <s> tags are purely "visual" and don't convey any semantic meaning.

I've <em>already</em> told you <em>four</em> times
that I do <em>not</em> like <i>The Lord of the Rings</i> movie.
Please, stop.

Nevertheless, these tags are not officially deprecated and not even marked as "not recommended" on MDN Web Docs and W3Schools.

For instance, here is a note from W3Schools:

> According to the HTML5 specification, the <b> tag should be used as a LAST resort when no other tag is more appropriate. The specification states that headings should be denoted with the <h1> to <h6> tags, emphasized text should be denoted with the <em> tag, important text should be denoted with the <strong> tag, and marked/highlighted text should be denoted with the <mark> tag.
>
> You can also use the following CSS to set bold text: "font-weight: bold;".

As you can see, though W3 article somewhat discourages to use <b>, it says nothing about why it is not deprecated at all.

Hence my questions:

  • Why these tags are not deprecated?
  • Whether we should replace them with CSS to better follow "separate content from presentation" idea?
  • In other words, is CSS font-weight: bold is really a 1-to-1 replacement for <b>? (and the same for <i>, <u>, <s>)

答案1

得分: 1

以下是翻译好的部分:

仍然有效的HTML元素

<b><i><s><u> 仍然是HTML Living Standards(截至2023年6月28日)- 文本级语义的一部分。

它们都已经在一定程度上被重新定义,不再是样式元素,而是更有语义的元素。

语义定义与它们旧的样式含义

<b> 以前表示加粗文本,但现在用于表示吸引注意力但没有传达额外重要性的文本,也没有替代语气或情绪的暗示,例如文档摘要中的关键词、评论中的产品名称、交互式文本驱动软件中的可操作词汇,或文章导语MDN喜欢称其为引起注意的文本

<i> 以前表示斜体文本,但现在用于表示具有不同质量的文本,与正常散文不同,表明不同质量的文本,例如分类名称、技术术语、来自其他语言的习惯用语、音译、思想或西方文本中的船名MDN喜欢称其为习惯用语文本

&lt;s&gt; 有时被解释为<s>删除线</s>文本,类似于 &lt;strike&gt;&lt;strike&gt; 已经被弃用,但 &lt;s&gt; 仍然存在,因为它具有语义含义:表示内容(单词、短语或陈述)不再准确或不再相关,但仍然显示以传达对文档的更改。MDN仍然称其为删除线文本,我更愿意称其为替代文本

&lt;u&gt; 以前只表示下划线文本,但现在用于表示具有未表达的非文本注释的文本(例如拼写错误的文本)。MDN喜欢称其为未表达的注释

因此,您不应该再使用这些标记来表示它们旧的样式含义。相反,如果它们的语义含义适用于您的内容,您应该使用它们。特别是对于 &lt;u&gt; 标记,最好添加CSS样式以使其与超链接区分开。例如:

<!-- 开始片段: js 隐藏: false 控制台: true Babel: false -->

<!-- 语言: lang-css -->

u {
  text-decoration: underline wavy red;
}

<!-- 语言: lang-html -->

<p>您可以使用&lt;code&gt;&amp;lt;u&amp;gt;&lt;/code&gt;标记来突出显示&lt;u&gt;拼写&lt;/u&gt;错误,以便作者可以&lt;u&gt;更正&lt;/u&gt;它们。</p>

<!-- 结束片段 -->

其他类似的HTML元素

还要注意,还有其他一些语义元素与 &lt;b&gt;&lt;i&gt; 有些相似:&lt;strong&gt;&lt;em&gt;。您可以参考它们的相应定义以获取详细信息。

MDN还在这里提供了更好的区分 &lt;strong&gt;&lt;b&gt; (链接),以及 &lt;em&gt;&lt;i&gt; (链接)

英文:

Still valid HTML elements

The &lt;b&gt;, &lt;i&gt;, &lt;s&gt; and &lt;u&gt; are still part of the HTML Living Standards (as at 28 June 2023) - Text-level semantics.

They have all been redefined to some degree to stop being style elements and instead be more semantic elements.

Semantic definitions vs their old style meaning

&lt;b&gt; used to mean bolded text, but is now used to repesent text to which attention is being drawn for utilitarian purposes without conveying any extra importance and with no implication of an alternate voice or mood, such as key words in a document abstract, product names in a review, actionable words in interactive text-driven software, or an article lede. MDN likes to call it the Bring Attention Text

&lt;i&gt; used to mean italicized text, but is now to bring alternate voice or mood, or otherwise offset from the normal prose in a manner indicating a different quality of text, such as a taxonomic designation, a technical term, an idiomatic phrase from another language, transliteration, a thought, or a ship name in Western texts. MDN likes to call it the Idiomatic Text

&lt;s&gt; has been somewhat interpreted as a <s>strikethrough</s> text, similar to &lt;strike&gt;. &lt;strike&gt; has been deprecated, but &lt;s&gt; has stayed on because it has semantic meaning: it represents content (word, phrase or statement) that is no longer accurate or no longer relevant but is still shown to convey change to the document. MDN still likes to call it the Strikethrough Text which I think dilutes it semantic meaning. I'd rather call it the Substituted Text.

&lt;u&gt; used to just mean underlined text, but is now used to represent span of text with an unarticulated non-textual annotation (e.g. text that is misspelt). MDN likes to call it the Unarticulated Annotation.

So you should not use these tags for their old styling meanings. Instead, you should use them if their semantic meanings apply to your content. Also, particularly for &lt;u&gt; tag, you should ideally add CSS styling to differentiate it from hyperlinks. For example:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

u {
  text-decoration: underline wavy red;
}

<!-- language: lang-html -->

&lt;p&gt;You could use the &lt;code&gt;&amp;lt;u&amp;gt;&lt;/code&gt; tag to highlight &lt;u&gt;speling&lt;/u&gt; mistakes, so the writer can &lt;u&gt;corect&lt;/u&gt; them.&lt;/p&gt;

<!-- end snippet -->

Other similar HTML elements

Also note there are other semantic elements which are somewhat similar to &lt;b&gt; and &lt;i&gt;: &lt;strong&gt; and &lt;em&gt;. You can refer to their corresponding definitions for details.

MDN also gives better differentiation between &lt;strong&gt; and &lt;b&gt; here as well as &lt;em&gt; and &lt;i&gt; here.

答案2

得分: 0

  • 一个原因是为了支持未积极开发/维护的旧网站,所以它没有被弃用。
  • 以我个人的看法,是的,它将内容与表示分开,并且鼓励/迫使我们提高CSS技能。但不是用来取代它,以某种方式它留下了结构痕迹。因为并不是所有的内容都会在浏览器中呈现,一些内容将被删除。我宁愿在容易且可能的情况下使用该标签,以满足您的需求。
  • 不,只是在视觉上。
英文:
  • One guest why it is not deprecated is to support old websites that are not actively developed/maintained.
  • IMHO yes it separates the content from the representation, and it also encourages/forces us to enhance CSS skills. But not to replace it, somehow it leaves a structural trace. Since not all will be rendered browser, some content will be scrapped. I rather use that tag, when it is easy and possible, so suits your need.
  • no, only visually.

huangapple
  • 本文由 发表于 2023年6月29日 09:44:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76577596.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定