font-weight 字体粗细

学习

font-weight 字体粗细

2026-02-23/0/ 编辑


font-weight 字体粗细

基本语法

font-weight: 粗细值;

关键字

说明对应数值
normal正常粗细400
bold加粗700
lighter比父元素更细-
bolder比父元素更粗-

数值

数值说明
100最细
200很细
300
400正常(默认)
500中等
600半粗
700
800很粗
900最粗

示例

<style>
  .box {
    font-weight: normal;  /* 正常值与400一样 */
  }
  .box2 {
    font-weight: bold;    /* bold与700一样 */
  }
  .box3 {
    font-weight: lighter; /* 比父元素更细 */
  }
  .box4 {
    font-weight: bolder;  /* 比父元素更粗 */
  }
</style>
<body>
  <div class="box">font-weight用来控制文字粗细</div>
  <div class="box2">加粗文字</div>
  <div class="box3">更细文字</div>
  <div class="box4">更粗文字</div>
</body>

实际应用

/* 标题加粗 */
h1, h2, h3 {
  font-weight: bold;
}

/* 强调文字 */
.highlight {
  font-weight: bold;
}

/* 次要文字 */
.muted {
  font-weight: normal;
}

学习要点

  1. 常用值: normal(400), bold(700)
  2. 数值范围: 100-900
  3. 相对值: lighter, bolder 相对于父元素
  4. 应用场景: 标题加粗、强调文字