font-weight

介绍

font-weight指定字体的粗细程度。有些自定义的字体如果只提供了normal类型的字形,则该属性不生效。

取值

  • 默认值 normal
    正常粗细。与400等值。

  • bold
    加粗。与700等值。

  • <number>
    介于 100-1000 之间的数字类型。更大的数值代表字体更粗。

/* Keyword values */
font-weight: normal;
font-weight: bold;

/* Numeric keyword values */
font-weight: 100;
font-weight: 200;
font-weight: 300;
font-weight: 400;
font-weight: 500;
font-weight: 600;
font-weight: 700;
font-weight: 800;
font-weight: 900;
font-weight: 1000;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

标准化语法

<font-weight> = normal | bold | [100, 1000]
1

与 Web 的区别

  • 不支持关键字borderlighter
  • 不支持全局关键字inheritinitial
  • 数值类型目前只支持1001000的整数值。
  • 字形映射失败的回退逻辑在不同平台和系统版本上会有差异。最坏情况可能会回退系统默认字体,导致自定义字体失效。

注意事项

  • 使用自定义字体时,最好不要使用font-weight,一般自定义字体都只包含normal类型的字形信息,会导致font-weight属性不生效,或回退到默认字体。

  • 在低于 Android10 的系统上,font-weight即使指定数值也会回退到normalbold两种字形上。

Last Updated: 2022/7/15 下午7:22:06