2.4 文本样式

文本样式控制字体、大小、行高、对齐方式等视觉表现,核心属性如下:

属性 描述 取值示例
font-family 设置字体族 font-family: "Microsoft YaHei", sans-serif;(优先使用微软雅黑,无则使用系统无衬线字体)
font-size 设置字体大小 font-size: 16px;(像素)、font-size: 1.2em;(相对父元素)、font-size: 120%;(相对父元素百分比)
font-weight 设置字重(粗细) font-weight: normal;(400)、font-weight: bold;(700)、font-weight: 500;(数值100-900)
line-height 设置行高(行间距) line-height: 1.5;(无单位时为字体大小的倍数,推荐)、line-height: 24px;(固定像素)
text-align 设置文本对齐方式 text-align: left/center/right/justify;
text-decoration 设置文本装饰线 text-decoration: none;(无装饰)、text-decoration: underline;(下划线)、text-decoration: line-through;(删除线)