教程 css tutorial

加粗与斜体

加粗和斜体是文本样式中最基本的强调方式,用于突出重点内容,提高阅读体验。

1. 加粗(font-weight)

通过设置 font-weight 属性调整字体粗细:

css
font-weight: normal;  /* 默认值,标准字体粗细 */
font-weight: bold;    /* 加粗 */
font-weight: 100-900; /* 数值,数字越大越粗 */

`

示例:

css
strong {
  font-weight: bold;
}

2. 斜体(font-style)

通过 font-style 属性设置字体是否倾斜:

css
font-style: normal;   /* 正常 */
font-style: italic;   /* 斜体 */
font-style: oblique;  /* 斜体(与 italic 类似) */

示例:

css
em {
  font-style: italic;
}

使用建议

  • 语义化标签 <strong> 和 <em> 对应加粗和斜体,更有利于无障碍和SEO。
  • 避免过度使用,保持文本层次清晰。