33

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

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

这会加粗整个段落:

<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>
4

7 回答 7

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

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

于 2012-01-30T01:32:18.150 回答
15

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

当想要为段落的特定部分设置样式时,请使用 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,1928 年 8 月 6 日 - 1987 年 2 月 22 日)是一位美国艺术家,他是被称为波普艺术的视觉艺术运动的领军人物。

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

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

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

于 2013-04-20T07:33:02.507 回答
7
<p><b> BOLD TEXT </b> not in bold </p>;

包括你想要在粗体之间的文本<b>...</b>

于 2012-01-30T05:38:10.267 回答
5

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

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

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.

于 2012-01-30T02:01:19.353 回答
3
<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

于 2012-08-12T05:49:06.523 回答
1

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

  1. 创建一个类以使任何项目变为粗体。因此,对于段落文本,它将是
span.bold(This name can be anything do not include parenthesis) {
   font-weight: bold;
}
  1. 在您的 html 中,您可以通过使用 span 标签并添加一个粗体类或您选择的任何名称来访问该类
于 2012-01-30T03:56:46.340 回答
1

添加<b>标签

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

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

于 2015-07-10T06:44:40.830 回答