CSS 字体设置详解 - font-family, font-size, font-weight, font-style
CSS 中的字体设置可以通过 font-family、font-size、font-weight、font-style 等属性来实现。下面详细介绍一下这些属性的用法。
font-family
font-family 属性用于设置字体,可以设置多个字体,以逗号分隔。如果第一个字体无法显示,则会依次尝试后面的字体。
示例:
body {
font-family: 'Helvetica Neue', Helvetica, sans-serif;
}
font-size
font-size 属性用于设置字体大小,可以使用绝对值或相对值。
示例:
h1 {
font-size: 36px;
}
p {
font-size: 1.2em;
}
font-weight
font-weight 属性用于设置字体粗细,可以设置 normal、bold、bolder、lighter 或数字(100-900)。
示例:
h1 {
font-weight: bold;
}
p {
font-weight: 300;
}
font-style
font-style 属性用于设置字体样式,可以设置 normal、italic 或 oblique。
示例:
h1 {
font-style: italic;
}
p {
font-style: oblique;
}
font
font 属性可以同时设置字体、字体大小、字体粗细和字体样式。
示例:
h1 {
font: bold 36px/1.5 'Helvetica Neue', Helvetica, sans-serif;
}
其中,36px 是字体大小,1.5 是行高,'Helvetica Neue', Helvetica, sans-serif 是字体。
原文地址: https://www.cveoy.top/t/topic/jM4Q 著作权归作者所有。请勿转载和采集!