属性 | 表示 | 注意点 |
---|---|---|
font-family | 字体 | 实际项目约定字体 |
font-size | 字号 | 单位px |
font-weight | 粗细 | 数字值 400 相当于 关键字 normal,700 等价于 bold 数字不带单位 |
font-style | 样式 | 默认normal 倾斜italic |
font | 连写 | 顺序不能颠倒,字号和字体必须写 |
字体系列
使用font-family
属性定义文本的字体系列
多个字体用逗号隔开,多单词的名字用引号,尽量使用系统默认字体
body {
font-family: 'Microsoft Yahei' , Arial;
}
字体大小
使用font-size
属性定义字体大小
标题标签
比较特殊,需要单独指定文字大小
body {
font-size: 20px;
}
字体粗细
使用font-weight
属性定义文字粗细
提倡使用数字
.bold {
font-weight: 700;
}
属性值 | 描述 |
---|---|
normal | 默认值,不加粗 |
bold | 定义粗体,加粗 |
100-900 | 数字值 400 相当于 关键字 normal,700 等价于 bold |
字体样式
使用font-style
属性设置文本的风格
属性值 | 作用 |
---|---|
normal | 默认值 |
italic | 使文本倾斜 |
.bold {
font-style: italic;
}
字体符合属性
- 顺序不能颠倒,各属性用空格隔开
- 不需要设置的属性可以省略,但必须保留
font-size
和font-family
,否则font不起作用
格式
/* font: font-style font-weight font-size/line-height font-family; */
body {
font: italic 700 50px 'Microsoft Yahei';
}
实例