CSS中常用的字体样式属性有font-family、font-size、font-weight、font-style、font-variant、color、line-height、text-align、text-indent、letter-spacing、word-spacing、text-transform、text-decoration等。
font-family
font-family属性用于设置字体类型,语法格式为:font-family:font-name,font-name,…。font-name可以是字体名称,也可以是关键字,如serif、sans-serif、monospace等。
p {
font-family: "Times New Roman", Times, serif;
}
font-size
font-size属性用于设置字体大小,语法格式为:font-size:length|percentage|initial|inherit。length可以是具体的数值,也可以使用相对单位,如em、rem等。
p {
font-size: 14px;
}
font-weight
font-weight属性用于设置字体的粗细,语法格式为:font-weight:normal|bold|bolder|lighter|number|initial|inherit。normal表示标准字体,bold表示粗体,bolder表示更粗的字体,lighter表示更细的字体,number表示粗细程度的数值。
p {
font-weight: bold;
}
font-style
font-style属性用于设置字体的样式,语法格式为:font-style:normal|italic|oblique|initial|inherit。normal表示标准字体,italic表示斜体,oblique表示倾斜字体。
p {
font-style: italic;
}
font-variant
font-variant属性用于设置字体的变体,语法格式为:font-variant:normal|small-caps|initial|inherit。normal表示标准字体,small-caps表示小型大写字体。
p {
font-variant: small-caps;
}
color
color属性用于设置字体的颜色,语法格式为:color:color|initial|inherit。color可以是颜色名称,也可以是RGB值,也可以是十六进制值。
p {
color: #000000;
}
line-height
line-height属性用于设置行高,语法格式为:line-height:length|percentage|normal|initial|inherit。length可以是具体的数值,也可以使用相对单位,如em、rem等。
p {
line-height: 1.5;
}
text-align
text-align属性用于设置文本的对齐方式,语法格式为:text-align:left|right|center|justify|initial|inherit。left表示左对齐,right表示右对齐,center表示居中对齐,justify表示两端对齐。
p {
text-align: center;
}
text-indent
text-indent属性用于设置文本缩进,语法格式为:text-indent:length|percentage|initial|inherit。length可以是具体的数值,也可以使用相对单位,如em、rem等。
p {
text-indent: 2em;
}
letter-spacing
letter-spacing属性用于设置字符间距,语法格式为:letter-spacing:length|normal|initial|inherit。length可以是具体的数值,也可以使用相对单位,如em、rem等。
p {
letter-spacing: 0.1em;
}
word-spacing
word-spacing属性用于设置单词间距,语法格式为:word-spacing:length|normal|initial|inherit。length可以是具体的数值,也可以使用相对单位,如em、rem等。
p {
word-spacing: 0.2em;
}
text-transform
text-transform属性用于设置文本的转换样式,语法格式为:text-transform:none|capitalize|uppercase|lowercase|initial|inherit。none表示不转换,capitalize表示首字母大写,uppercase表示全部大写,lowercase表示全部小写。
p {
text-transform: uppercase;
}
text-decoration
text-decoration属性用于设置文本的装
千锋教育是高品质web前端培训机构,千锋教育拥有大量实力web前端培训讲师,提供优质的web培训课程,web前端培训,欢迎报名千锋教育。