在CSS中,引用外部字体是非常重要的,它可以提高网站的可读性和视觉效果。但如果需要使用多个外部字体,应该怎么做呢?下面让我们来一起学习。首先,我们需要在CSS文件中定义fontface规则,该规则将告...
在CSS中,引用外部字体是非常重要的,它可以提高网站的可读性和视觉效果。但如果需要使用多个外部字体,应该怎么做呢?下面让我们来一起学习。
首先,我们需要在CSS文件中定义@font-face规则,该规则将告诉浏览器这个字体的来源、文件格式和字体的名称。例如,我们在声明“Roboto”的字体时可以这样写:
CSS
@font-face {
font-family: 'Roboto';
src: url('https://fonts.googleapis.com/css?family=Roboto&display=swap') format('woff2');
font-weight: normal;
font-style: normal;
} CSS
h1{
font-family: 'Roboto', sans-serif;
} CSS
@font-face {
font-family: 'Roboto';
src: url('https://fonts.googleapis.com/css?family=Roboto&display=swap') format('woff2');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'Lora';
src: url('https://fonts.googleapis.com/css?family=Lora&display=swap') format('woff2');
font-weight: normal;
font-style: normal;
}
h1{
font-family: 'Lora', serif;
}
p{
font-family: 'Roboto', sans-serif;
}