在CSS中,我们可以通过fontweight属性来调整字体的粗细。这个属性接受多种值,如normal、bold、bolder、lighter等等。使用normal值时,字体的粗细会被设置为默认值,一般...
在CSS中,我们可以通过font-weight属性来调整字体的粗细。这个属性接受多种值,如normal、bold、bolder、lighter等等。
使用normal值时,字体的粗细会被设置为默认值,一般来说是正常的400。
使用bold值时,字体的粗细会被设置为比normal值更加粗细一些的700。如果需要更加粗细的字体,可以使用bolder值或者在font-weight的值上直接输入更大的数值。
使用lighter值时,字体的粗细会被设置为比normal值更加轻一些的200。同样地,可以使用在font-weight的值上直接输入更小的数值来获取更细的字体。
除了这些值以外,我们还可以在CSS中使用自定义的字体粗细类型。在字体文件中,一般会有不同粗细类型的字体,如Regular、Medium、Bold等等。我们可以使用这些类型名来设置字体的粗细。
例如,如果我们有一个名为“Montserrat”的字体,该字体包含Regular、Medium、Bold三种粗细类型。我们可以按照以下方式来设置字体的粗细:
@font-face {
font-family: 'Montserrat';
src: url('Montserrat-Regular.ttf') format('truetype');
font-weight: normal;
}
@font-face {
font-family: 'Montserrat';
src: url('Montserrat-Medium.ttf') format('truetype');
font-weight: medium;
}
@font-face {
font-family: 'Montserrat';
src: url('Montserrat-Bold.ttf') format('truetype');
font-weight: bold;
}
p {
font-family: 'Montserrat', sans-serif;
font-weight: medium;
}