我想在我的网站上使用谷歌的Roboto字体,我正在遵循这个教程:

http://www.maketecheasier.com/use-google-roboto-font-everywhere/2012/03/15

我下载了一个文件夹结构如下所示的文件:

现在我有三个问题:

我有css在我的media/css/main.css url。我需要把文件夹放在哪里呢? 我需要提取所有的eot,svg等从所有子文件夹,并放在字体文件夹? 我需要创建css文件fonts.css和包括在我的基本模板文件?

他的例子是这样的

@font-face {
    font-family: 'Roboto';
    src: url('Roboto-ThinItalic-webfont.eot');
    src: url('Roboto-ThinItalic-webfont.eot?#iefix') format('embedded-opentype'),
         url('Roboto-ThinItalic-webfont.woff') format('woff'),
         url('Roboto-ThinItalic-webfont.ttf') format('truetype'),
         url('Roboto-ThinItalic-webfont.svg#RobotoThinItalic') format('svg'); (under the Apache Software License). 
    font-weight: 200;
    font-style: italic;
}

我的url应该是什么样的,如果我想有dir结构像:

/media/fonts/roboto


当前回答

你真的不需要做这些。

去谷歌的网页字体页面 在右上方的搜索框中搜索Roboto 选择要使用的字体的变体 点击顶部的“选择此字体”,选择你需要的权重和字符集。

该页面将为您提供一个<link>元素,以包含在您的页面中,以及一个示例字体家族规则列表,以用于您的CSS。

以这种方式使用谷歌的字体可以保证可用性,并减少您自己服务器的带宽。

其他回答

对于网站,您可以使用“Roboto”字体如下:

如果你已经创建了单独的css文件,那么在css文件的顶部放置以下行:

@import url('https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,500,500i,700,700i,900,900i');

或者如果你不想创建单独的文件,那么在<style>…</style>:

<style>
  @import url('https://fonts.googleapis.com/css? 
  family=Roboto:300,300i,400,400i,500,500i,700,700i,900,900i');
</style>

然后:

html, body {
    font-family: 'Roboto', sans-serif;
}

老帖子了,我知道。

这也可以使用CSS @import url:

@import url(http://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300ita‌​lic,400italic,500,500italic,700,700italic,900italic,900);
html, body, html * {
  font-family: 'Roboto', sans-serif;
}

你看过压缩文件里的How_To_Use_Webfonts.html了吗?

在阅读之后,似乎每个字体子文件夹都有一个已经创建的.css,你可以通过包括以下内容来使用:

<link rel="stylesheet" href="stylesheet.css" type="text/css" charset="utf-8" />

花了一个小时,解决了字体问题。

相关答案-以下是React.js网站:

Install the npm module: npm install --save typeface-roboto-mono import in .js file you want to use one of the below: import "typeface-roboto-mono"; // if import is supported require('typeface-roboto-mono') // if import is not supported For the element you can use one of the below: fontFamily: "Roboto Mono, Menlo, Monaco, Courier, monospace", // material-ui font-family: Roboto Mono, Menlo, Monaco, Courier, monospace; /* css */ style="font-family:Roboto Mono, Menlo, Monaco, Courier, monospace;font-weight:300;" /*inline css*/

希望这能有所帮助。

试试这个

<style>
@font-face {
        font-family: Roboto Bold Condensed;
        src: url(fonts/Roboto_Condensed/RobotoCondensed-Bold.ttf);
}
@font-face {
         font-family:Roboto Condensed;
        src: url(fonts/Roboto_Condensed/RobotoCondensed-Regular.tff);
}

div1{
    font-family:Roboto Bold Condensed;
}
div2{
    font-family:Roboto Condensed;
}
</style>
<div id='div1' >This is Sample text</div>
<div id='div2' >This is Sample text</div>