如何在 HTML/CSS 中将段落中的单词加粗?

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

how to bold words within a paragraph in HTML/CSS?

htmlcssparagraph

提问by user1111042

I am a beginner in web programming and have some very simple questions.

我是网络编程的初学者,有一些非常简单的问题。

I'm trying to bold several words in one paragraph but I don't know how to do that using HTML/CSS. I've figured out how to bold entire paragraphs, but not individual words yet. How can I bold one word, like "bold" in my example?

我试图在一个段落中加粗几个单词,但我不知道如何使用 HTML/CSS 来做到这一点。我已经想出了如何加粗整个段落,但还没有加粗单个单词。我怎样才能加粗一个词,比如我的例子中的“bold”?

This bolds an entire paragraph:

这将整个段落加粗:

<html>
<head>
<style type="text/css">
p.n1
{
    font:15px bold 30px Georgia,serif;
}

</style>
</head>

<body>
<p class="n1">I am in bold. </p>
</body>
</html>

回答by Mike Hofer

<p><strong>This is in bold.</strong> This is not.</p>

You might find Mozilla Developer Networkto be a very handy and reliable reference.

您可能会发现Mozilla Developer Network是一个非常方便和可靠的参考。

回答by Michael Anderson - NinjaSush2

I know this question is old but I ran across it and I know other people might have the same problem. All these answers are okay but do not give proper detail or actual TRUE advice.

我知道这个问题很老,但我遇到了它,我知道其他人可能有同样的问题。所有这些答案都可以,但没有提供适当的细节或实际的 TRUE 建议。

When wanting to style a specific section of a paragraph use the span tag.

当想要为段落的特定部分设置样式时,请使用 span 标签。

<p><span style="font-weight:900">Andy Warhol</span> (August 6, 1928 - February 22, 1987) 

was an American artist who was a leading figure in the visual art movement known as pop 

art.</p>

Andy Warhol(August 6, 1928 - February 22, 1987) was an American artist who was a leading figure in the visual art movement known as pop art.

安迪·沃霍尔Andy Warhol,1928 年 8 月 6 日 - 1987 年 2 月 22 日)是一位美国艺术家,他是被称为波普艺术的视觉艺术运动的领军人物。

As the code shows, the span tag styles on the specified words: "Andy Warhol". You can further style a word using any CSS font styling codes.

如代码所示,span 标签样式在指定的单词上:“Andy Warhol”。您可以使用任何 CSS 字体样式代码进一步设置一个单词的样式。

{font-weight; font-size; text-decoration; font-family; margin; color}, etc. 

Any of these and more can be used to style a word, group of words, or even specified paragraphs without having to add a class to the CSS Style Sheet Doc. I hope this helps someone!

这些中的任何一个都可用于设置一个单词、一组单词甚至指定段落的样式,而无需向 CSS 样式表文档添加类。我希望这可以帮助别人!

回答by Rodrigo

if you want to just "bold", Mike Hofer's answeris mostly correct.

如果您只想“大胆”,Mike Hofer 的回答大多是正确的。

but notice that the tag bolds its contents by default, but you can change this behavior using css, example:

但请注意,该标签默认将其内容加粗,但您可以使用 css 更改此行为,例如:

p strong {
    font-weight: normal;
    font-style: italic;
}

Now your "bold" is italic :)

现在你的“粗体”是斜体:)

So, try to use tags by its meaning, not by its default style.

因此,请尝试根据其含义使用标签,而不是根据其默认样式。

回答by user1177371

<p><b> BOLD TEXT </b> not in bold </p>;

Include the text you want to be in bold between <b>...</b>

包括要加粗的文本 <b>...</b>

回答by swati16

<style type="text/css">
p.boldpara {font-weight:bold;}
</style>
</head>

<body>
<p class="boldpara">Stack overflow is good site for developers. I really like this site </p>

</body>

</html>

http://www.tutorialspoint.com

http://www.tutorialspoint.com

回答by coletrain

Although your answer has many solutions I think this is a great way to save lines of code. Try using spans which is great for situations like yours.

尽管您的答案有很多解决方案,但我认为这是节省代码行的好方法。尝试使用跨度,这对于您这样的情况非常有用。

  1. Create a class for making any item bold. So for paragraph text it would be
  1. 创建一个使任何项目加粗的类。所以对于段落文本,它将是
span.bold(This name can be anything do not include parenthesis) {
   font-weight: bold;
}
span.bold(This name can be anything do not include parenthesis) {
   font-weight: bold;
}
  1. In your html you can access that class like by using the span tags and adding a class of bold or whatever name you have chosen
  1. 在您的 html 中,您可以通过使用 span 标签并添加一个粗体类或您选择的任何名称来访问该类

回答by mee

Add <b>tag

添加<b>标签

<p> <b> I am in Bold </b></p>

For more text formatting tags click here

有关更多文本格式标签,请单击此处