我的代码有问题.因为我想为我的页面包含一个全局字体,我下载了一个.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
}
Run Code Online (Sandbox Code Playgroud)
我不知道哪里出错了.你能帮帮我吗?谢谢.
Abh*_*yal 134
仅为webfont提供.ttf文件对于跨浏览器支持来说不够好.目前最好的组合是使用以下组合:
@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 */
}
Run Code Online (Sandbox Code Playgroud)
此代码假定您具有.eot,.woff,.ttf和svg格式的webfont.要自动完成所有这些过程,您可以使用:Font-Squirrel:Web Font Generator.
此外,现代浏览器正在转向.woff字体,所以你也可以这样做:
@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 */
}
Run Code Online (Sandbox Code Playgroud)
点击此处了解更多信息:http://css-tricks.com/snippets/css/using-font-face/
寻找浏览器支持:我可以使用fontface
小智 18
你尝试过格式吗?
@font-face {
font-family: 'The name of the Font Family Here';
src: URL('font.ttf') format('truetype');
}
Run Code Online (Sandbox Code Playgroud)
阅读这篇文章:http://css-tricks.com/snippets/css/using-font-face/
此外,可能还取决于浏览器.
Bla*_*ebb 14
I know this is an old post but this solved my problem.
@font-face{
font-family: "Font Name";
src: url("../fonts/font-name.ttf") format("truetype");
}Run Code Online (Sandbox Code Playgroud)
请注意,src:url("../fonts/font-name.ttf");我们使用两个句点返回根目录,然后进入字体文件夹或文件所在的任何位置。
希望这对某人有所帮助:) 快乐编码
INT*_*DAN 11
你可以使用这样的字体:
@font-face {
font-family:"Name-Of-Font";
src: url("yourfont.ttf") format("truetype");
}Run Code Online (Sandbox Code Playgroud)