如何包括一个字体.ttf使用CSS? [英] How to include a font .ttf using CSS?

查看:648
本文介绍了如何包括一个字体.ttf使用CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码有问题。因为我想为我的页面包括一个全局字体,我下载了一个.ttf文件。

I have a problem with my code. Because I want to include a global font for my page and I downloaded a .ttf file. And I include it in my main CSS but my font wont change.

这是我的简单代码:

@font-face {
    font-family: 'oswald';
    src: url('/font/oswald.regular.ttf');
}

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
    margin:0;
    padding:0;
    border:0;
    font-size:100%;
    font:inherit;
    font-family: oswald;
    vertical-align:baseline
} 

我不知道我错了。你能帮我这个吗?感谢。

I don't know where did I go wrong. Can you help me with this? Thanks.

推荐答案

只有为webfont提供.ttf文件不足以支持跨浏览器。目前最好的组合是使用组合:

Only providing .ttf file for webfont won't be good enough for cross-browser support. The best possible combination at present is using the combination as :

@font-face {
  font-family: 'MyWebFont';
  src: url('webfont.eot'); /* IE9 Compat Modes */
  src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
       url('webfont.woff') format('woff'), /* Modern Browsers */
       url('webfont.ttf')  format('truetype'), /* Safari, Android, iOS */
       url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
}

此代码假设您有.eot,.woff ,.ttf和svg格式为你webfont。要自动执行所有此过程,您可以使用: Font-Squirrel:Web字体生成器

This code assumes you have .eot , .woff , .ttf and svg format for you webfont. To automate all this process , you can use : Font-Squirrel : Web Font Generator.

此外,现代浏览器正在转向.woff字体,因此您也可以这么做:

Also , modern browsers are shifting towards .woff font , so you can probably do this too : :

@font-face {
  font-family: 'MyWebFont';
  src: url('myfont.woff') format('woff'), /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
   url('myfont.ttf') format('truetype'); /* Chrome 4+, Firefox 3.5, Opera 10+, Safari 3—5 */
}  

点击此处了解详情: http://css-tricks.com/snippets/css/using- font-face /

查找浏览器支持:我可以使用fontface

Look for browser support : Can I Use fontface

这篇关于如何包括一个字体.ttf使用CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆