CSS 如何使用css使我的字体加粗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/991160/
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
How to make my font bold using css?
提问by Wolfr
I'm very new to HTML and CSS and I was just wondering how I could make my font bold using CSS.
我对 HTML 和 CSS 非常陌生,我只是想知道如何使用 CSS 使我的字体加粗。
I have a plain HTML page that imports a CSS file, and I can change the font in the CSS. But I don't know how to make the font bold, can anyone help me?
我有一个导入 CSS 文件的纯 HTML 页面,我可以更改 CSS 中的字体。但是我不知道如何使字体变粗,有人可以帮助我吗?
回答by Wolfr
You can use the CSS declaration font-weight: bold;
.
您可以使用 CSS 声明font-weight: bold;
。
I would advise you to read the CSS beginner guide at http://htmldog.com/guides/cssbeginner/.
我建议您阅读http://htmldog.com/guides/cssbeginner/ 上的 CSS 初学者指南。
回答by erenon
You can use the strong
elementin html, which is great semantically (also good for screen readers etc.), which typicallyrenders as bold text:
您可以使用html 中的strong
元素,这在语义上很好(也适用于屏幕阅读器等),通常呈现为粗体文本:
See here, some <strong>emphasized text</strong>.
Or you can use the font-weight
css propertyto style any element's text as bold:
或者你可以使用的font-weight
CSS属性样式的任何元素的文本为粗体:
span { font-weight: bold; }
<p>This is a paragraph of <span>bold text</span>.</p>
回答by David Wolever
You'd use font-weight: bold
.
你会用font-weight: bold
.
Do you want to make the entire document bold? Or just parts of it?
您想让整个文档加粗吗?还是只是其中的一部分?
回答by merkuro
Sine you are new to html here are three ready to use examples on how to use CSS together with html. You can simply put them into a file, save it and open it up with the browser of your choice:
由于您是 html 的新手,这里有三个关于如何将 CSS 与 html 一起使用的准备使用示例。您可以简单地将它们放入一个文件中,保存并使用您选择的浏览器打开它:
This one directly embeds your CSS style into your tags/elements. Generally this is not a very nice approach, because you should always separate the content/html from design.
这个直接将您的 CSS 样式嵌入到您的标签/元素中。通常这不是一个很好的方法,因为您应该始终将内容/html 与设计分开。
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Hi, I'm bold!</title>
</head>
<body>
<p style="font-weight:bold;">Hi, I'm very bold!</p>
</body>
</html>
The next one is a more general approach and works on all "p" (stands for paragraph) tags in your document and additionaly makes them HUGE. Btw. Google uses this approach on his search:
下一个是更通用的方法,适用于文档中的所有“p”(代表段落)标签,并且使它们变得很大。顺便提一句。谷歌在他的搜索中使用了这种方法:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Hi, I'm bold!</title>
<style type="text/css">
p {
font-weight:bold;
font-size:26px;
}
</style>
</head>
<body>
<p>Hi, I'm very bold and HUGE!</p>
</body>
</html>
You probably will take a couple of days playing around with the first examples, however here is the last one. In this you finally fully seperate design (css) and content (html) from each other in two different files. stackoverflow takes this approach.
您可能需要花几天时间来处理第一个示例,但这是最后一个示例。在这里,您最终在两个不同的文件中完全分离了设计 (css) 和内容 (html)。stackoverflow 采用这种方法。
In one file you put all the CSS (call it 'hello_world.css'):
将所有 CSS 放在一个文件中(称为“hello_world.css”):
p {
font-weight:bold;
font-size:26px;
}
In another file you should put the html (call it 'hello_world.html'):
在另一个文件中,您应该放置 html(称为“hello_world.html”):
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Hi, I'm bold!</title>
<link rel="stylesheet" type="text/css" href="hello_world.css" />
</head>
<body>
<p>Hi, I'm very bold and HUGE!</p>
</body>
</html>
Hope this helps a little. To address specific elements in your document and not all tags you should make yourself familiar with the class
, id
and name
attributes. Have fun!
希望这有所帮助。要处理文档中的特定元素而不是所有标签,您应该熟悉class
,id
和name
属性。玩得开心!
回答by clawr
Use the CSS font-weight
property
使用 CSSfont-weight
属性
回答by Santosh Khalse
Selector name{
font-weight:bold;
}
Suppose you want to make bold for p element
假设你想为 p 元素加粗
p{
font-weight:bold;
}
You can use other alternative value instead of bold like
您可以使用其他替代值而不是粗体
p{
font-weight:bolder;
font-weight:600;
}
回答by Ian Boyd
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<STYLE type="text/css">
body
{
font-weight: bold;
}
</STYLE>
</HEAD>
<BODY>
Body text is now bold.
</BODY>
</HTML>
回答by OutOfMemory
font-weight: bold
回答by Luixv
font-weight: bold;
字体粗细:粗体;
回答by Andrew Tuzson
You could use a couple approaches. First would be to use the strong tag
您可以使用几种方法。首先是使用强标签
Here is an <strong>example of that tag</strong>.
Another approach would be to use the font-weight property. You can achieve inline, or via a class or id. Let's say you're using a class.
另一种方法是使用 font-weight 属性。您可以实现内联,也可以通过类或 id 实现。假设您正在使用一个类。
.className {
font-weight: bold;
}
Alternatively, you can also use a hard value for font-weight and most fonts support a value between 300 and 700, incremented by 100. For example, the following would be bold:
或者,您也可以为 font-weight 使用硬值,大多数字体支持 300 到 700 之间的值,递增 100。例如,以下将是粗体:
.className {
font-weight: 700;
}