替代 HTML 粗体标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/649305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:27:37  来源:igfitidea点击:

Alternative to the HTML Bold tag

htmlcss

提问by Darryl Hein

Okay, so I know that in HTML you can use the <b>tag, but isn't there a "weight=bold"attribute that I can use in the <p>tag?

好的,所以我知道在 HTML 中您可以使用<b>标签,但是没有"weight=bold"我可以在<p>标签中使用的属性吗?

Or is that in CSS, or Javascript?

还是在 CSS 或 Javascript 中?

回答by Darryl Hein

Also consider the <strong>tag. It's much better for screen readers and therefore better for accessibility. Search engines also use <strong>tags to determine important content similar to how they use header tags <h1>, <h2>, etc (although <b>will also have similar meaning to search engines). If you want to stress importance of text, use <strong>. If you don'twant to stress importance, use the <b>tag or use the font-weight:bold;style on the element or in the CSS.

还要考虑<strong>标签。它更适合屏幕阅读器,因此更适合可访问性。搜索引擎也使用<strong>标签来确定类似于他们如何使用标题标签的重要内容<h1><h2>等等(虽然<b>也会有类似的含义,搜索引擎)。如果您想强调文本的重要性,请使用<strong>. 如果你希望压力的重要性,使用<b>标签或使用font-weight:bold;风格的元素或CSS。

Although, if you are bolding the entire paragraph, it's probably better to use the CSS option. This will reduce the affect on screen readers and it probably doesn't make sense to have an entire paragraph emphasized. But on the other hand, I've seen bold used to emphasize an entire paragraph before for good reason. In which case, font-weight:bold;is what you want to use, likely in a class/style.

但是,如果您将整个段落加粗,使用 CSS 选项可能会更好。这将减少对屏幕阅读器的影响,并且强调整个段落可能没有意义。但另一方面,我曾经看到过粗体用于强调整个段落是有充分理由的。在这种情况下,font-weight:bold;是您想要使用的,可能在类/样式中。

In the end, <strong>, <b>or font-weight:bold;will all work and accomplish something similar visually (probably exactly the same), but they have slightly different meanings. Also, make sure that if what you're bolding is a header, use the header tags: <h1>, <h2>, etc.

最后,<strong>, <b>orfont-weight:bold;都可以工作并在视觉上完成类似的事情(可能完全相同),但它们的含义略有不同。此外,确保,如果你是加粗是标题,使用标题标签:<h1><h2>,等。

回答by mipadi

You're thinking of the CSS property font-weight:

您正在考虑 CSS 属性font-weight

p { font-weight: bold; }

回答by alex

If the text's meaning is semantically strong, use the strongelement. If not, use a semantic named class (one that clearly shows the meaning of the element, don't mix presentation and data by calling it boldetc) and reference it in your CSS.

如果文本的含义在语义上很强,请使用该strong元素。如果没有,请使用语义命名类(一个清楚地显示元素含义的类,不要通过调用bold等方式混合表示和数据)并在您的 CSS 中引用它。

HTML

HTML

<span class="important-message">I'm important!</span>

CSS

CSS

.important-message {
   font-weight: bold;
}

Some people still use the belement as a presentational hook, but it hasn't been deprecated, though most people favour the strongelement nowadays. Just make sure they are used correctly.

有些人仍然使用该b元素作为展示钩子,但它并没有被弃用,尽管现在大多数人都喜欢这个strong元素。只要确保它们被正确使用。

回答by user336882

The <b>tag is alive and well. <b> is not deprecated, but its use has been clarified and limited. <b> has no semantic meaning, nor does it convey vocal emphasis such as might be spoken by a screen reader. <b> does, however, convey printed empasis, as does the <i> tag. Both have a specific place in typograpghy, but not in spoken communication, mes frères.

所述的<b>标签是生命力。<b> 没有被弃用,但它的使用已经被澄清和限制。<b> 没有语义意义,也不会传达诸如屏幕阅读器可能会说出的语音强调。然而, <b> 确实传达了印刷的 empasis,就像 <i> 标签一样。两者在排版中都有特定的位置,但在口语交流中没有,我是frères

To quote from http://www.whatwg.org/

引用自http://www.whatwg.org/

The b element represents a span of text to be stylistically offset from the normal prose without conveying any extra importance, such as key words in a document abstract, product names in a review, or other spans of text whose typical typographic presentation is boldened.
b 元素代表一段文本,在文体上与普通散文有所偏移,但不传达任何额外的重要性,例如文档摘要中的关键词、评论中的产品名称,或其他典型排版显示加粗的文本。

回答by Nasser Hadjloo

You can make text or words Boldwith using <b>Text</b>tag.

您可以Bold使用<b>Text</b>标签制作文本或单词。

You can also use <strong>Text</strong>tag

你也可以使用<strong>Text</strong>标签

Head tags <h1>, <h2>, <h3>, ... are default bolded tags and make your text Bold by default unless you change their style with CSS

Head 标签<h1>, <h2>, <h3>, ... 是默认的粗体标签,除非您使用 CSS 更改它们的样式,否则默认情况下将您的文本设为粗体

Above tags was available in HTML but if you like to change the style with CSSyou can use

以上标签在 HTML 中可用,但如果您想更改样式,CSS可以使用

font-weight:bold

回答by serioys sam

Its in CSS you have to set font-weight: bold;as style

它在 CSS 中你必须设置font-weight: bold;为样式

回答by user9073024

You can code like below..

你可以像下面这样编码..

<html>
 <head>
 <style>
 p.boldstats{
 font-weight: bold
  }
  </style>
 </head>

  <body>
  <p class="boldstats"> The bold finder </p>
  </body>
</html>

回答by Oluwasayo Babalola

You can use the font-weight attribute on your

您可以在您的字体上使用 font-weight 属性

For example:

例如:

<p>This is my paragraph</p>

You can either have your CSS inline as below:

您可以将 CSS 内联如下:

<p style="font-weight:bold;">This is my paragraph</p>

Or have it in your external CSS stylesheet as below:

或者将它放在您的外部 CSS 样式表中,如下所示:

p{
  font-weight:bold;
}

回答by Julian Aubourg

It's all historical and dates from a time where dinosaurs walked the earth and CSS didn't exist.

这都是历史性的,可以追溯到恐龙在地球上行走而 CSS 不存在的时代。

More seriously, forget about the <b/>tag and use font-weight:boldin a CSS rule :)

更严重的是,忘记<b/>标签并font-weight:bold在 CSS 规则中使用 :)

回答by John Boker

you could also do <p style="font-weight:bold;"> bold text here </p>

你也可以这样做 <p style="font-weight:bold;"> bold text here </p>