为什么@ font-face无法正常工作? [英] Why is @font-face not working?

查看:87
本文介绍了为什么@ font-face无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 @ font-face 在我正在设计的网站上使用自定义字体.我不知道为什么这次不起作用.我以前用过,没问题.

I am trying to use @font-face to use a custom font on a site I'm designing. I can't figure out why it's not working this time. I've used it before with no problem.

这是我的代码(不是来自实际站点,而是我用来测试问题的简化版本):

Here is my code(not from the actual site, but a simplified version I used to test the issue):

html

<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
<link rel="stylesheet" type="text/css" href="./css/stylesheet.css">
</head>
<body>
<p>Loremm ipsum</p>
</body>
</html>

css(我留了复位键)

css(I left the reset in)

/*--------------------------*/
/*----------RESET-----------*/
/*--------------------------*/

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

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;
    vertical-align: baseline;
    font-family:myfont;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

/*-------------------------*/
/*-----------MAIN----------*/
/*-------------------------*/

@font-face {
    font-family:myfont;
    src:url('./fonts/myfont.ttf'),
        url('./fonts/myfont.eot');
}

我的index.html在 html/

my index.html is in html/

我的字体文件位于 html/fonts/

我的CSS位于 html/css/

任何人都可以看到问题吗?

Can anyone see the problem?

我已经在chrome和firefox中对其进行了测试,并且可以在计算机上进行编辑.

I have tested this in chrome and firefox and it is on my computer for editing.

推荐答案

我将猜测您的src是相对于CSS文件位置的,而您的'./'却无法将您带到正确的目录.给src指定一个绝对的字体地址,并确保它能正常工作.

I'm going to make a guess that your src is relative to your CSS file location and your './' is not getting you to the right directory. Give the src an absolute address to your font and make sure it works that way.

我也看不到将字体家族应用于任何元素的位置.

I also don't see where you apply the font-family to any of your elements.

这篇关于为什么@ font-face无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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