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

谁说胖子不能爱 提交于 2019-12-09 02:15:12

问题


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?

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>

回答1:


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

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




回答2:


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.

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

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

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.

{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!




回答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




回答4:


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.




回答5:


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

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




回答6:


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



回答7:


Add <b> tag

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

For more text formatting tags click here



来源:https://stackoverflow.com/questions/9058425/how-to-bold-words-within-a-paragraph-in-html-css

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!