Google Web字体

Sou*_*rav 2 html css fonts google-font-api

我打算在我的网站上使用Google网络字体.
我的网站有很多页面,但只有几个CSS文件.
- =>有没有办法在CSS文件中添加这个标签(因为我不想编辑所有的HTML文件)?

<link href=' http://fonts.googleapis.com/css?family=Droid+Sans' rel='stylesheet' type='text/css'>
Run Code Online (Sandbox Code Playgroud)

或者我是否需要在每个HTML页面的头部添加上述行?

Dan*_*n F 5

是的,@import在谷歌字体- 的jsfiddle示例

把它放在CSS文件的顶部

@import url('http://fonts.googleapis.com/css?family=Droid+Sans');
Run Code Online (Sandbox Code Playgroud)

然后,像平常一样参考它

h1 { font-family: 'Droid Sans', arial, serif; font-size:24pt;}
Run Code Online (Sandbox Code Playgroud)

  • 值得注意的是@import会影响性能并且应该避免,请参阅https://developers.google.com/speed/docs/best-practices/rtt#AvoidCssImport和http://developer.yahoo.com/performance/rules .html#csslink了解更多信息. (2认同)