css font 字体

有时候网站中某些地方的文字需要加粗显示,表示它是重要的信息,可以使用 cssfont-weight属性用于设置字体的粗细。

当然你也可以使用<strong>重要内容</strong>标签来解决这个问题,但是它的粗细比较固定,这里不做讨论。

语法

该语法比较简单,如下:

font-weight:value
其中value可以取到的值为:

  • 100~900:400 等同于 normal,而 700 等同于 bold。
  • normal:默认值,不加粗
  • bold: 粗体。
  • bolder:更粗。
  • lighter:比normal细。

例子

<!DOCTYPE html>
<html>
<title>css 字体粗细 font-weight</title>
<body>
<p style="font-weight:bold;">此字体为粗体。</p>
<p style="font-weight:bolder;">这个字体比较粗。</p>
<p style="font-weight:lighter;">这个字体比较轻。</p>
<p style="font-weight:100;">这个字体是100 weight.</p>
<p style="font-weight:200;">这个字体是200 weight.</p>
<p style="font-weight:300;">这个字体是300 weight.</p>
<p style="font-weight:400;">这个字体是400 weight.</p>
<p style="font-weight:500;">这个字体是500 weight.</p>
<p style="font-weight:600;">这个字体是600 weight.</p>
<p style="font-weight:700;">这个字体是700 weight.</p>
<p style="font-weight:800;">这个字体是800 weight.</p>
<p style="font-weight:900;">这个字体是900 weight.</p>
</body>

</html> 
输出如下:

css font-weight 设置字体的粗细