如何使 HTML 中的文本加粗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1082353/
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-29 00:07:31  来源:igfitidea点击:

How do I make text bold in HTML?

csshtml

提问by user133145

I'm trying to make some text bold using HTML, but I'm struggling to get it to work.

我正在尝试使用 HTML 将一些文本加粗,但我正在努力让它工作。

Here's what I'm trying:

这是我正在尝试的:

Some <bold>text</bold> that I want emboldened.

Could someone tell me what I'm doing wrong?

有人能告诉我我做错了什么吗?

回答by Andrija

use <strong>or <b>tag

使用<strong><b>标记

also, you can try with css <span style="font-weight:bold">text</span>

另外,您可以尝试使用 css <span style="font-weight:bold">text</span>

回答by Joey

HTML doesn't have a <bold>tag, instead you would have to use <b>. Note however, that using <b>is discouraged in favor of CSS for a while now. You would be better off using CSS to achieve that.

HTML 没有<bold>标签,您必须使用<b>. 但是请注意,<b>现在不鼓励使用CSS 来支持 CSS。你最好使用 CSS 来实现这一点。

The <strong>tag is a semantic element for strong emphasis which defaultsto bold.

<strong>标记是着重强调其语义元素默认为粗体。

回答by Sampson

The Markup Way:

标记方式:

<strong>I'm Bold!</strong> and <b>I'm Bold Too!</b>

The Styling Way:

造型方式:

.bold {
  font-weight:bold;
}

<span class="bold">I'm Bold!</span>

From: http://www.december.com/html/x1/

<b>

This element encloses text which should be rendered by the browser as boldface. Because the meaning of the B element defines the appearance of the content it encloses, this element is considered a "physical" markup element. As such, it doesn't convey the meaning of a semantic markup element such as strong.

<strong>

Description This element brackets text which should be strongly emphasized. Stronger than the em element.

来自:http: //www.december.com/html/x1/

<b>

此元素包含应由浏览器呈现为粗体的文本。由于 B 元素的含义定义了它所包含的内容的外观,因此该元素被视为“物理”标记元素。因此,它不传达诸如strong之类的语义标记元素的含义。

<strong>

说明 此元素将应强烈强调的文本括在括号中。比em元素强。

回答by Geo

In Html use:

在 HTML 中使用:

  • Some <b>text</b>that I want emboldened.
  • Some <strong>text</strong>that I want emboldened.
  • 一些我想要加胆的<b>文字</b>
  • 一些我想要加胆的<strong>文字</strong>

In CSS use:

在 CSS 中使用:

  • Some <span style="font-weight:bold">text</span>that I want emboldened.
  • 一些我想要加胆的<span style="font-weight:bold">文字</span>

回答by Benjamin Hawkes-Lewis

Could someone tell me what I'm doing wrong?"

有人能告诉我我做错了什么吗?”

"bold" has never been an HTML element ("b" is the closest match).

“粗体”从来都不是 HTML 元素(“b”是最接近的匹配项)。

HTML should contain structured content; publisher CSS should suggest styles for that content. That way user agents can expose the structured content with useful styling and navigational controls to users who can't see your suggested bold styling (e.g. users of search engines, totally blind users using screen readers, poorly sighted users using their own colors and fonts, geeky users using text browsers, users of voice-controlled, speaking browsers like Opera for Windows). Thus the right way to make text bold depends on whyyou want to style it bold. For example:

HTML 应包含结构化内容;发布者 CSS 应该建议该内容的样式。这样,用户代理可以向看不到您建议的粗体样式的用户(例如搜索引擎的用户、使用屏幕阅读器的完全失明的用户、使用自己的颜色和字体的视力不佳的用户)公开具有有用的样式和导航控件的结构化内容,使用文本浏览器的极客用户,使用语音控制的语音浏览器(如 Windows 版 Opera)的用户)。因此,使文本加粗的正确方法取决于您为什么要将其设置为粗体。例如:

  • Want to distinguish headings from other text? Use heading elements ("h1" to "h6") and suggest a bold style for them within your CSS ("h1, h2, h3, h4, h5, h6 {font-weight: bold;}".

  • Want to embolden labels for form fields? Use a "label" element, programmatically associate it with the the relevant "select", "input" or "textarea" element by giving it a "for" attribute matching an "id" attribute on the target, and suggest a bold style for it within your CSS ("label {font-weight: bold;"}).

  • Want to embolden a heading for a group of related fields in a form, such as a group of radio choices? Surround them with a "fieldset" element, give it a "legend" element, and suggest a bold style for it within your CSS ("legend {font-weight: bold;}").

  • Want to distinguish a table caption from the table it captions? Use a "caption" element and suggest a bold style for it within your CSS ("caption {font-weight: bold;}").

  • Want to distinguish table headings from table data cells? Use a "th" element and suggest a bold style for it within your CSS ("th {font-weight: bold;}").

  • Want to distinguish the title of a referenced film or album from surrounding text? Use a "cite" element with a class ("cite class="movie-title"), and suggest a bold style for it within your CSS (".movie-title {font-weight: bold;}").

  • Want to distinguish a defined keyword from the surrounding text defining or explaining it? Use a "dfn" element and suggest a bold style for it within your CSS ("dfn {font-weight: bold;}").

  • Want to distinguish some computer code from surrounding text? Use a "code" element and suggest a bold style for it within your CSS ("code {font-weight: bold;}").

  • Want to distinguish a variable name from surrounding text? Use a "var" element and suggest a bold style for it within your CSS ("var {font-weight: bold;}").

  • Want to indicate that some text has been added as an update? Use an "ins" element and suggest a bold style for it within your CSS ("ins {font-weight: bold;}").

  • Want to lightly stress some text ("I lovekittens!")? Use an "em" element and suggest a bold style for it within your CSS (e.g. "em {font-weight: bold;}").

  • Want to heavily stress some text, perhaps for a warning ("Beware the dog!")? Use a "strong" element and suggest a bold style for it within your CSS (e.g. "strong {font-weight: bold;}").

  • 想要将标题与其他文本区分开来?使用标题元素(“h1”到“h6”)并在你的 CSS 中为它们建议一个粗体样式(“h1, h2, h3, h4, h5, h6 {font-weight: bold;}”。

  • 想要为表单域添加标签?使用“label”元素,通过为其赋予与目标上的“id”属性匹配的“for”属性,以编程方式将其与相关的“select”、“input”或“textarea”元素相关联,并建议使用粗体样式它在你的 CSS 中(“label {font-weight: bold;”})。

  • 想要为表单中的一组相关字段(例如一组单选选项)添加标题?用“fieldset”元素包围它们,给它一个“legend”元素,并在你的CSS中为它建议一个粗体样式(“legend {font-weight:bold;}”)。

  • 想要将表格标题与其标题的表格区分开来?使用“标题”元素并在您的 CSS 中为其建议粗体样式(“标题{font-weight:bold;}”)。

  • 想要区分表格标题和表格数据单元格?使用“th”元素并在您的 CSS 中为其建议粗体样式(“th {font-weight: bold;}”)。

  • 想要将引用的电影或专辑的标题与周围的文本区分开来吗?使用带有类的“cite”元素(“cite class="movie-title"),并在你的 CSS 中为它建议一个粗体样式(“.movi​​e-title {font-weight: bold;}”)。

  • 想要将定义的关键字与定义或解释它的周围文本区分开来?使用“dfn”元素并在您的 CSS 中为其建议粗体样式(“dfn {font-weight: bold;}”)。

  • 想要将一些计算机代码与周围的文本区分开来吗?使用“代码”元素并在您的 CSS 中为其建议粗体样式(“code {font-weight: bold;}”)。

  • 想要将变量名称与周围的文本区分开来?使用“var”元素并在您的 CSS 中为其建议粗体样式(“var {font-weight: bold;}”)。

  • 想要表明已添加一些文本作为更新?使用“ins”元素并在您的 CSS 中为其建议粗体样式(“ins {font-weight: bold;}”)。

  • 想要轻轻强调一些文字(“我小猫!”)?使用“em”元素并在您的 CSS 中为其建议粗体样式(例如“em {font-weight: bold;}”)。

  • 想要强调一些文本,也许是为了警告(“小心狗!”)?使用“strong”元素并在您的 CSS 中为其建议粗体样式(例如“strong {font-weight: bold;}”)。

… You get the idea (hopefully).

......你明白了(希望如此)。

Can't find an HTML element with the right semanticsto express /why/ you want to make this particular text bold? Wrap it in a generic "span" element, give it a meaningful class name that expresses your rationale for distinguishing that text ("<span class="lede">Let me begin this news article with a sentence that summarizes it.</span>), and suggest a bold style for it within your CSS (".lede {font-weight: bold;"}. Before making up your own class names, you might want to check if there's a microformat (microformats.org) or common convention for what you want to express.

找不到具有正确语义的 HTML 元素来表达/为什么/您要将此特定文本设为粗体?将它包裹在一个通用的“span”元素中,给它一个有意义的类名,表达你区分该文本的基本原理(“<span class="lede">让我用一个总结它的句子开始这篇新闻。</span >),并在你的 CSS 中为它建议一个粗体样式 (".lede {font-weight: bold;"}。在创建你自己的类名之前,你可能想检查一下是否有微格式 (microformats.org) 或您想要表达的内容的通用约定。

回答by Muhammad Awais

The HTML element defines bold text, without any extra importance.

HTML 元素定义了粗体文本,没有任何额外的重要性。

<b>This text is bold</b>

The HTML element defines strong text, with added semantic "strong" importance.

HTML 元素定义了强文本,增加了语义“强”的重要性。

<strong>This text is strong</strong>

回答by Muhammad Awais

Another option is to do it via CSS ...

另一种选择是通过 CSS ...

E.g. 1

例如 1

<span style="font-weight: bold;">Hello stackoverflow!</span>

E.g. 2

例如 2

<style type="text/css">
    #text
    {
        font-weight: bold;
    }
</style>

<div id="text">
    Hello again!
</div>

回答by 1010

You're nearly there!

你快到了!

For a bold text, you should have this: <b> bold text</b>or <strong>bold text</strong>They have the same result.

对于粗体文本,你应该有这个:<b> bold text</b>或者 <strong>bold text</strong>他们有相同的结果。

Working example - JSfiddle

工作示例 - JSfiddle

回答by Gumbo

It's just <b>instead of <bold>:

它只是<b>代替<bold>

Some <b>text</b> that I want bolded.

Note that <b>just changes the appearance of the text. If you want to render it bold because you want to express a strong emphasis, you should better use the <strong>element.

请注意,这<b>只是改变了文本的外观。如果你想把它加粗,因为你想表达一个强烈的强调,你最好使用<strong>元素

回答by John Saunders

I think the real answer is http://www.w3schools.com/HTML/default.asp.

我认为真正的答案是http://www.w3schools.com/HTML/default.asp