我想为我的页面包含一个全局字体。我下载了一个 .ttf 文件,并将其包含在我的 CSS 中,但我的字体不会改变。
这是我的代码:
@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
}
我哪里做错了?
原文由 Jerielle 发布,翻译遵循 CC BY-SA 4.0 许可协议
只为 webfont 提供 .ttf 文件不足以支持跨浏览器。目前最好的组合是使用组合作为:
此代码假定您的 webfont 具有 .eot 、 .woff 、 .ttf 和 svg 格式。要自动执行所有这些过程,您可以使用: Transfonter.org 。
此外,现代浏览器正在转向 .woff 字体,因此您也可以这样做:
在此处阅读更多内容:http: //css-tricks.com/snippets/css/using-font-face/
寻找浏览器支持: Can I Use fontface