在CSS中,我们可以使用font-weight属性来设定字体的宽度。这个属性的取值可以是数字、关键字或者是百分比。
font-weight: bold;
font-weight: 700;
font-weight: bolder;
font-weight: lighter;
font-weight: normal;
font-weight: 200;
font-weight: 300;
font-weight: 400;
font-weight: 500;
font-weight: 600;
font-weight: ***;
font-weight: 900;
font-weight: 100%;
font-weight: inherit; 其中,数字取值为100-900,100表示最细,900表示最粗。关键字可以是bold,bolder,lighter,normal。我们可以使用这些属性来设置字体粗细,效果如下:
p {
font-weight: bold;
} 这样就可以将所有p标签中的文字设为粗体。
还有一种常用的方法是使用粗体的字体,比如微软雅黑的粗体,用于配合数字取值,可以设置一个更细的粗体,效果如下:
p {
font-weight: 600;
font-family: "微软雅黑 Bold";
} 这样就可以将p标签中的文字变为比较粗的微软雅黑粗体。
当然,font-weight属性不止于字体的粗细,它也可以用来设置特定的字体变种,比如italic,oblique等
。p {
font-style: italic;
font-weight: 400;
} 在这个例子中,我们使用font-style属性来设定斜体,font-weight属性来设定粗细。这样就可以很容易地在CSS中设置一个粗细合适、斜体的字体样式。