我在Google字体中使用过如何设置字体的建议。所以我做了以下行动:
1)在页面上添加了这个依赖项:
<link href="https://fonts.googleapis.com/css?family=Roboto:100,400,700&subset=cyrillic-ext" rel="stylesheet">
2)将CSS设置为body标签:
html, body {
font-family: 'Roboto', sans-serif;
background: #f7f7f7;
}
当我尝试为其他元素设置字体时:
a {
font-family: Roboto-Light;
}
它不起作用。
答案 0 :(得分:2)
a {
font-family: 'Roboto'; /* You don't need this since you say html {font-family: 'Roboto'}*/
font-weight: 100;
}
/*Font's family name need to be inside quotes "MyFontName"
答案 1 :(得分:1)
Roboto
和Roboto-Light
是两种不同的字体。当您使用Roboto-Light
时,它不知道您想要Roboto
的瘦字体粗细。它只查找名为Roboto-Light
的任何字体,您没有加载,定义或声明。
你可能想要使用类似的东西:
a {
font-weight: 100;
}
它将使用Roboto
font-face,因为它已经在body
上设置在任何元素上,但现在将使用100
font-weight,这是真的,真的很瘦。
答案 2 :(得分:1)
要将任何Google字体嵌入网页,请执行以下操作(Roboto Light示例):
请参阅下面的HTML示例:
<html>
<head>
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Roboto:300">
<style>
body {
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: 48px;
}
</style>
</head>
<body>
<div>Making the Web Beautiful!</div>
</body>
</html>