HTML5中的vs

前端之家收集整理的这篇文章主要介绍了HTML5中的vs前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直难以决定何时使用b以及何时使用span. b元素的新语义看起来很模糊.

The b element represents a span of 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

听起来就像你不能使用strong,em或i时使用的标签.

The b element should be used as a last resort when no other element is
more appropriate.

但是,当短语内容还没有适用的标签时,我们已经获得了span.

The span element doesn’t mean anything on its own… It represents its
children.

有一个示例用途列表

key words in a document abstract,product names in a review,
actionable words in interactive text-driven software,or an article
lede

但是我找不到将它们联系在一起的基本原则,而不是将它们塑造成大胆的. old spec甚至提到了风格:

The b element represents a span of text to be stylistically offset
from the normal prose [emphasis added]

样式是为CSS.我们还建议使用类来显示实际含义

authors can use the class attribute on the b element to identify why
the element is being used

这听起来好像使用太多,不能单独按标签分组.我也可以使用类来解释span的语义.

The span element… can be useful when used together with the global
attributes,e.g. class,lang,or dir.

例子

如果我想要这个:

Your score for CS 101 Final is 42%.

我写吗

Your score for <b>CS 101 Final</b> is 42%.

要么

Your score for <span>CS 101 Final</span> is 42%.

或者对于这个:

Answer: 42

可不可能是

<b>Answer</b> 42

要么

<span>Answer</span> 42

(它只是一个键值对,因此定义列表不适用.)

我不仅仅想知道各个例子的正确标签.我想知道为什么他们是对的.我用什么标准来决定b或span标签

解决方法

第一个例子相当简单.你试图让“CS 101 Final”引人注目,因为它比“你的得分”文本更重要.所以那是

< strong> CS 101 Final< / strong>的得分是42%.

使用< b>,你不是想要引起注意.您希望均匀地读取整个文本,但是您将某些单词和短语标记为对读者有用(实用目的).坦率地说,这个用途并不多.该规范给出了冒险游戏和报告中关键字的示例,但要找到很多用途并不容易.

第二个例子比较棘手.在这里,“答案”在风格上被抵消了. “答案”这个词绝对不比实际答案文本重要,也不需要因任何其他原因引起读者的特别注意.它只是被标记为与实际答案文本不同.然而,在“没有专用元素的常用习语”部分中的规范建议使用< b>.在对话中标记说话者,使用它可以被视为与此类似.但基本上它只是造型,所以< span>一堂课很可能是最好的选择.

What criteria do I use to decide on a b or a span tag?

从上面可以看出,这是一个消除过程.是< strong>或者< em>或者<引用>适当?是的 – 使用它们.否 – 是< b>或者< i>适当?是的 – 使用它们.不,然后使用< span>

原文链接:https://www.f2er.com/html5/168811.html

猜你在找的HTML5相关文章