<strong> 和 <small> 标签一起使用时的正确用法

Correct usage of <strong> and <small> tags when used together

考虑到 <strong><small> 标签都是内联的,哪种用法在语义上应该被认为是正确的?

案例 1:

<strong><small>Some text</small></strong>

案例二:

<small><strong>Some text</strong></small>

这有关系吗?

一些文字

一些文字

他们俩会做同样的事情。它将加粗文本并降低其字体大小。

没关系

<strong> 生成 font-weight: bold;<small> 生成 font-size: smaller;,两者都不会相互覆盖。

任何做过搜索引擎优化的人都知道 h1 标签使第 1 页到第 30 页的排名有很大的不同。所以是的,这些标签确实有其重要性,但如何呢? 我是复制粘贴官方解释,下面是我后续的问题

<b> vs. <strong>

It is often confusing to new developers why there are so many ways to express the same thing on a rendered website. and are perhaps one of the most common sources of confusion, causing developers to ask "Should I use or ? Don't they both do the same thing?"

Not exactly. The element is for content that is of greater importance, while the element is used to draw attention to text without indicating that it's more important.

It may help to realize that both are valid and semantic elements in HTML5 and that it's a coincidence that they both have the same default styling (boldface) in most browsers (although some older browsers actually underline ). Each element is meant to be used in certain types of scenarios, and if you want to bold text for decoration, you should instead actually use the CSS font-weight property.

The intended meaning or purpose of the enclosed text should be what determines which element you use. Communicating meaning is what semantics are all about.

<em> vs. <strong>

Adding to the confusion is the fact that while HTML 4 defined as indicating a stronger emphasis, HTML 5 defines as representing "strong importance for its contents." This is an important distinction to make.

While is used to change the meaning of a sentence as spoken emphasis does ("I love carrots" vs. "I love carrots"), is used to give portions of a sentence added importance (e.g., "Warning! This is very dangerous.") Both and can be nested to increase the relative degree of importance or stress emphasis, respectively.

The HTML <small> element represents side-comments and small print, like copyright and legal text, independent of its styled presentation. By default, it renders text within it one font-size smaller, such as from small to x-small.

问题是它们是否都具有预定义的行为并且除了视觉吸引力之外什么都不做。因为粗体意味着重要,而强意味着视觉上重要。那么这种行为针对的是谁。我们通常不会去查看源代码吧?

答案是 BOTS,最重要的是索引、抓取 BOTS。如果您正在进行 SEO 和某种内容分析或从中解析这些内容,那么这些标签会派上用场。除此之外,它与

没有什么不同
<i><b>hello</b></i>

<b><i>hello</i></b>

<small><strong>hello</strong></small>

<strong><small>hello</small></strong>

是的,它们确实很重要,具体取决于您的具体情况。除了视觉人类阅读之外,如果我期望很多计算机可读性,例如文本到语音、机器人或辅助显示等,那么这些很重要。

粗体:标记我爸爸让我做某事

strong: tag 我爸爸用坚定的指导语气告诉我做某事

斜体:它是内容的一部分,但不是内容流,如果您错过了也没关系

小:它是内容的一部分,但不是内容流,但如果您错过了它,我们可能会回来说您应该阅读它。

从内容营销的角度来看,上述区别在计算机要解析的源代码中起着重要作用。

句法的角度来看,两者都可以使用。由于两者都是可以包含其他短语内容的 phrasing content 元素,因此它们都同样有效 HTML.


语义的角度来看,请确保正确使用每个标签:

<small> 不应用于将文本设置为较小的样式。它应该只用于提供语义意义——

...side-comments and small print, like copyright and legal text, independent of its styled presentation.

同样,<strong> 不应用于使文本加粗。它应该只用于表示——

...that its contents have strong importance, seriousness, or urgency.

这些标签也不应包含超出其需要的内容。例如,您可能有这样的法律文本,其中只有一部分文本非常重要:

<p><small>Copyright Foobar Industries, 2021. <strong>Do not reprint without permission.</strong></small></p>

如果您的旁注或小字的 完整 非常重要,您可以使用任何一种方法。它们在语义上是等价的并且在句法上是有效的。