本文介绍了&LT b取代; vs< span>在HTML5中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我一直很难决定何时使用b以及何时使用span。 元素看起来很模糊。

听起来像这样当你不能使用strong,em或i时,你使用的标签。

但是我们已经有了一个适用的标签。

有一个示例用途列表

但我找不到一个将它们全部结合在一起的基本原则,而不是将它们设计为粗体。 甚至提及款式:b
$ b

样式用于CSS。我们还建议使用类来显示实际含义

这使得听起来像使用过于分散,无法单独使用标签进行分组。我还可以使用类来解释span的语义。



示例



如果我想要:

我写作

  < b> CS 101 Final< / b>是42%。 

 您的分数为< span> CS 101最终< / span>是42%。 

或者这个:

会是

 < b>回答< / b> 42 

 <跨度>应答和LT; /跨度> 42 

(这只是一个键值对,所以定义列表不适用。)



我不只是想知道各个示例的正确标记。我想知道他们为什么是正确的。我使用什么标准来决定b或span标签? 解决方案

第一个例子非常简单。你试图使CS 101 Final引起注意,因为它比你的得分文本更重要重要。那就是



< strong> CS 101 Final< / strong>的分数是42%。



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

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

正如你从上面看到的,这是一个消除的过程。 < strong> 或< em> 或< cite> 合适吗?是的 - 使用它们。否 - < b> 或< i> 合适吗?是的 - 使用它们。否,请使用< span>


I've been having difficulty deciding when to use b and when to use span. The new semantics of the b element seem vague.

It sounds like that tag you use when you can't use strong, em, or i.

But we've already got span for when phrasing content doesn't already have an applicable tag.

There's a list of example uses

But I can't find an underlying principle that ties them all together other than styling them bold. The old spec even mentions style:

Styling is for CSS. We're also advised to use classes to show what the actual meaning is

Which makes it sound like the uses are too divergent to be grouped by the tag alone. I can also use classes to explain the semantics of span.

Examples

If I want this:

do I write

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

or

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

Or for this one:

would it be

<b>Answer</b> 42

or

<span>Answer</span> 42

(It's only one key-value pair, so definition list would not apply.)

I'm not just interested in knowing the correct tags for the individual examples. I'd like to know why they're correct. What criteria do I use to decide on a b or a span tag?

解决方案

The first example is fairly straightforward. You are trying to make "CS 101 Final" catch the eye, because it's more important than the "Your score for" text is. So that's

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

With <b>, you're not trying to catch the eye. You want the whole text to be read evenly, but you marking certain words and phrases as being of use to the reader (utilitarian purposes). Frankly, there aren't many uses for this. The spec gives examples of keywords in an adventure game and in a report but it's not easy to find many uses.

The second example is trickier. Here, "Answer" is being stylistically offset. The word "Answer" is definitely not more important than the actual answer text, nor does it need to be brought to the particular attention of the reader for any other reason. It's just being marked as distinct from the actual answer text. However, the spec, in the "Common idioms without dedicated elements" section, suggests the use of <b> to mark the speaker in a conversation, and using it could be seen as being analogous to that. But basically it's just styling, so <span> with a class is likely the best choice.

As you can see from the above, it's a process of elimination. Is <strong> or <em> or <cite> appropriate? Yes - use them. No - Is <b> or <i> appropriate? Yes - use them. No then use <span>

这篇关于&LT b取代; vs&lt; span&gt;在HTML5中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 19:45