我想在我的网站上使用Google的Roboto字体,我正在关注本教程:
http://www.maketecheasier.com/use-google-roboto-font-everywhere/2012/03/15
我已经下载了具有如下文件夹结构的文件:
现在我有三个问题:
media/css/main.css
网址中有css .那么我需要将该文件夹放在哪里?fonts
文件夹?他使用这个例子
@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;
}
Run Code Online (Sandbox Code Playgroud)
我的网址应该是什么样子,如果我想要像dir结构那样:
/media/fonts/roboto
小智 230
你真的不需要做任何这些.
Roboto
在搜索框右上方该页面将为您提供<link>
要包含在页面中的元素,以及font-family
要在CSS中使用的示例规则列表.
使用Google的字体可以保证可用性,并减少自己服务器的带宽.
Ash*_*ngh 60
您可以采用两种方法在您的网页上使用许可的网络字体:
Typekit,Fonts.com,Fontdeck等字体托管服务为设计人员提供了一个简单的界面来管理所购买的字体,并生成指向提供字体的动态CSS或JavaScript文件的链接.谷歌甚至提供这项服务免费(这里是您所要求的字体的Roboto的例子).Typekit是唯一提供额外字体提示的服务,以确保字体在浏览器中占据相同的像素.
像Google和Typekit(即WebFont加载器)使用的JS字体加载器提供CSS类和回调来帮助管理可能发生的FOUT,或者在下载字体时响应超时.
<head>
<!-- get the required files from 3rd party sources -->
<link href='http://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
<!-- use the font -->
<style>
body {
font-family: 'Roboto', sans-serif;
font-size: 48px;
}
</style>
</head>
Run Code Online (Sandbox Code Playgroud)DIY方法涉及获得许可供Web使用的字体,以及(可选)使用FontSquirrel的生成器(或某些软件)等工具来优化其文件大小.然后,使用标准@font-face
CSS属性的跨浏览器实现来启用字体.
这种方法可以提供更好的负载性能,因为您可以更精细地控制要包含的字符,从而控制文件大小.
/* get the required local files */
@font-face {
font-family: 'Roboto';
src: url('roboto.eot'); /* IE9 Compat Modes */
src: url('roboto.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('roboto.woff') format('woff'), /* Modern Browsers */
url('roboto.ttf') format('truetype'), /* Safari, Android, iOS */
url('roboto.svg#svgFontName') format('svg'); /* Legacy iOS */
}
/* use the font */
body {
font-family: 'Roboto', sans-serif;
font-size: 48px;
}
Run Code Online (Sandbox Code Playgroud)使用字体托管服务和@ font-face声明可以在整体性能,兼容性和可用性方面提供最佳输出.
资料来源:http://www.artzstudio.com/2012/02/web-font-performance-weighing-fontface-options-and-alternatives/
UPDATE
您现在可以使用此处的说明手动生成Roboto字体.
roc*_*ady 15
老帖子,我知道.
这也可以使用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;
}
Run Code Online (Sandbox Code Playgroud)
int*_*ika 13
@font-face {
font-family: 'Roboto';
src: url('../font/Roboto-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
/* etc, etc. */
Run Code Online (Sandbox Code Playgroud)
@font-face
font-family: 'Roboto'
src: local('Roboto'), local('Roboto-Regular'), url('../fonts/Roboto-Regular.ttf') format('truetype')
font-weight: normal
font-style: normal
@font-face
font-family: 'Roboto'
src: local('Roboto Bold'), local('Roboto-Bold'), url('../fonts/Roboto-Bold.ttf') format('truetype')
font-weight: bold
font-style: normal
@font-face
font-family: 'Roboto'
src: local('Roboto Italic'), local('Roboto-Italic'), url('../fonts/Roboto-Italic.ttf') format('truetype')
font-weight: normal
font-style: italic
@font-face
font-family: 'Roboto'
src: local('Roboto BoldItalic'), local('Roboto-BoldItalic'), url('../fonts/Roboto-BoldItalic.ttf') format('truetype')
font-weight: bold
font-style: italic
@font-face
font-family: 'Roboto'
src: local('Roboto Light'), local('Roboto-Light'), url('../fonts/Roboto-Light.ttf') format('truetype')
font-weight: 300
font-style: normal
@font-face
font-family: 'Roboto'
src: local('Roboto LightItalic'), local('Roboto-LightItalic'), url('../fonts/Roboto-LightItalic.ttf') format('truetype')
font-weight: 300
font-style: italic
@font-face
font-family: 'Roboto'
src: local('Roboto Medium'), local('Roboto-Medium'), url('../fonts/Roboto-Medium.ttf') format('truetype')
font-weight: 500
font-style: normal
@font-face
font-family: 'Roboto'
src: local('Roboto MediumItalic'), local('Roboto-MediumItalic'), url('../fonts/Roboto-MediumItalic.ttf') format('truetype')
font-weight: 500
font-style: italic
/* Roboto-Regular.ttf 400 */
/* Roboto-Bold.ttf 700 */
/* Roboto-Italic.ttf 400 */
/* Roboto-BoldItalic.ttf 700 */
/* Roboto-Medium.ttf 500 */
/* Roboto-MediumItalic.ttf 500 */
/* Roboto-Light.ttf 300 */
/* Roboto-LightItalic.ttf 300 */
/* https://fonts.google.com/specimen/Roboto#standard-styles */
Run Code Online (Sandbox Code Playgroud)
在src
直接引用的字体文件,因此,如果你把所有的人对/media/fonts/roboto
你应该是指他们在您的main.css这样的:
src: url('../fonts/roboto/Roboto-ThinItalic-webfont.eot');
在..
进入一个文件夹了,这意味着你指的是media
文件夹,如果该main.css的是在/media/css
文件夹中。
您必须../fonts/roboto/
在 CSS 中的所有 url 引用中使用(并确保文件在此文件夹中,而不是在子目录中,例如roboto_black_macroman
)。
基本上(回答您的问题):
我的 media/css/main.css url 中有 css。那么我需要把那个文件夹放在哪里
你可以把它留在那里,但一定要使用 src: url('../fonts/roboto/
我是否需要从所有子文件夹中提取所有 eot、svg 等并放入 fonts 文件夹中
如果您想直接引用这些文件(不将子目录放在 CSS 代码中),那么可以。
我是否需要创建 css 文件 fonts.css 并包含在我的基本模板文件中
不一定,您可以在 main.css 中包含该代码。但将字体与自定义 CSS 分开是一种很好的做法。
这是我使用的字体 LESS/CSS 文件的示例:
@ttf: format('truetype');
@font-face {
font-family: 'msb';
src: url('../font/msb.ttf') @ttf;
}
.msb {font-family: 'msb';}
@font-face {
font-family: 'Roboto';
src: url('../font/Roboto-Regular.ttf') @ttf;
}
.rb {font-family: 'Roboto';}
@font-face {
font-family: 'Roboto Black';
src: url('../font/Roboto-Black.ttf') @ttf;
}
.rbB {font-family: 'Roboto Black';}
@font-face {
font-family: 'Roboto Light';
src: url('../font/Roboto-Light.ttf') @ttf;
}
.rbL {font-family: 'Roboto Light';}
Run Code Online (Sandbox Code Playgroud)
(在这个例子中,我只使用了 ttf)然后我@import "fonts";
在我的 main.less 文件中使用(less 是一个 CSS 预处理器,它使这样的事情更容易一些)
小智 5
对于网站,您可以使用“Roboto”字体,如下所示:
如果您创建了单独的 css 文件,则在 css 文件顶部放置以下行:
@import url('https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,500,500i,700,700i,900,900i');
Run Code Online (Sandbox Code Playgroud)
或者,如果您不想创建单独的文件,则在中间添加上一行<style>...</style>
:
<style>
@import url('https://fonts.googleapis.com/css?
family=Roboto:300,300i,400,400i,500,500i,700,700i,900,900i');
</style>
Run Code Online (Sandbox Code Playgroud)
然后:
html, body {
font-family: 'Roboto', sans-serif;
}
Run Code Online (Sandbox Code Playgroud)