CSS教程
CSS进阶

如何在CSS中加粗文本?

CSS中的 font-weight 属性用于设置字体的粗细或粗细。它指定文本中字符的宽度或粗细。 font-weight 属性取决于浏览器指定的权重或字体系列中可用的字体。这个CSS属性定义了从薄到厚的字符。
它接受预定义的数字值或关键字值。我们可以与此属性一起使用的可用关键字为 normal、bold、bolder和lighter。数值可以是100、200、300,.........,最多为900。较高的数值表示的字体粗细比较低的数值大。

语法

font-weight: normal | bold | bolder | lighter | number | initial | inherit;
以上语法中的 number代表数字值。数值 400 与关键字值 normal 相同,值 700 与关键字值 bold相同>。
normal 值定义普通字符,而 bold 值指定粗体字符。 bolder 值表示字体粗体,而 lighter 值表示字体粗体比从父级继承的字体粗。
通过插图说明如何在 CSS 中加粗文本。

示例

<!DOCTYPE html>
<html>
<body>
<style>
p{
font-size: 20px;
}
</style>
<p style="font-weight: normal;">This font is normal.</p>
<p style="font-weight: bold;">This font is bold.</p>
<p style="font-weight: lighter;">This font is lighter.</p>
<p style="font-weight: bolder;">This font is bolder.</p>
<p style="font-weight: 100;">This font is 100 weight.</p>
<p style="font-weight: 200;">This font is 200 weight.</p>
<p style="font-weight: 300;">This font is 300 weight.</p>
<p style="font-weight: 400;">This font is 400 weight.</p>
<p style="font-weight: 500;">This font is 500 weight.</p>
<p style="font-weight: 600;">This font is 600 weight.</p>
<p style="font-weight: 700;">This font is 700 weight.</p>
<p style="font-weight: 800;">This font is 800 weight.</p>
<p style="font-weight: 900;">This font is 900 weight.</p>
</body>
</html>
输出
如何以粗体显示CSS
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4