我想在我的网站上使用谷歌的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字体,这意味着它们是不同的字体

操作:roboto_regular_macroman

使用它们中的任何一个:

1-解压文件夹的字体你想使用

2-上传到CSS文件附近

3-现在包括在CSS文件

示例:包含名为"roboto_regular_macroman"的字体:

@font-face {
font-family: 'Roboto';
src: url('roboto_regular_macroman/Roboto-Regular-webfont.eot');
src: url('roboto_regular_macroman/Roboto-Regular-webfont.eot?#iefix') format('embedded-opentype'),
     url('roboto_regular_macroman/Roboto-Regular-webfont.woff') format('woff'),
     url('roboto_regular_macroman/Roboto-Regular-webfont.ttf') format('truetype'),
     url('roboto_regular_macroman/Roboto-Regular-webfont.svg#RobotoRegular') format('svg');
font-weight: normal;
font-style: normal;
}

注意文件的路径,这里我上传了一个名为“roboto_regular_macroman”的文件夹,与CSS所在的文件夹相同

那么你现在只需输入font-family: 'Roboto'就可以使用字体了;

其他回答

你真的不需要做这些。

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

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

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

很容易

你下载的每个文件夹都有不同的roboto字体,这意味着它们是不同的字体

操作:roboto_regular_macroman

使用它们中的任何一个:

1-解压文件夹的字体你想使用

2-上传到CSS文件附近

3-现在包括在CSS文件

示例:包含名为"roboto_regular_macroman"的字体:

@font-face {
font-family: 'Roboto';
src: url('roboto_regular_macroman/Roboto-Regular-webfont.eot');
src: url('roboto_regular_macroman/Roboto-Regular-webfont.eot?#iefix') format('embedded-opentype'),
     url('roboto_regular_macroman/Roboto-Regular-webfont.woff') format('woff'),
     url('roboto_regular_macroman/Roboto-Regular-webfont.ttf') format('truetype'),
     url('roboto_regular_macroman/Roboto-Regular-webfont.svg#RobotoRegular') format('svg');
font-weight: normal;
font-style: normal;
}

注意文件的路径,这里我上传了一个名为“roboto_regular_macroman”的文件夹,与CSS所在的文件夹相同

那么你现在只需输入font-family: 'Roboto'就可以使用字体了;

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

相关答案-以下是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*/

希望这能有所帮助。

在CSS样式表中的字体类型名称之前使用/fonts/或/font/。我面对这个错误,但之后它的工作很好。

@font-face {
    font-family: 'robotoregular';
    src: url('../fonts/Roboto-Regular-webfont.eot');
    src: url('../fonts/Roboto-Regular-webfont.eot?#iefix') format('embedded-opentype'),
         url('../fonts/Roboto-Regular-webfont.woff') format('woff'),
         url('../fonts/Roboto-Regular-webfont.ttf') format('truetype'),
         url('../fonts/Roboto-Regular-webfont.svg#robotoregular') format('svg');
    font-weight: normal;
    font-style: normal;

}

对于网站,您可以使用“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;
}