未找到 CSS 定义的字体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10361200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 03:43:55  来源:igfitidea点击:

CSS-defined font not found

csswebfonts

提问by Shawn de Wet

Possible Duplicate:
@font-face not working on a client site?

可能重复:
@font-face 不在客户端站点上工作?

I have the following font files in this folder structure in my ASP.Net MVC web app:

我的 ASP.Net MVC Web 应用程序的此文件夹结构中有以下字体文件:

-[root]

-[根]

|-- Public

|-- 公开

||--fonts

||--字体

|||--NuvoWeb-Medi.eot

|||--NuvoWeb-Medi.eot

|||--NuvoWeb-Medi.woff

|||--NuvoWeb-Medi.woff

In my CSS file I have the following font declaration:

在我的 CSS 文件中,我有以下字体声明:

@font-face 
{
    font-family: NuvoWeb;
    src: url(/Public/fonts/NuvoWeb-Medi.eot);
}
@font-face 
{
    font-family: NuvoWeb;
    src: url(/Public/fonts/NuvoWeb-Medi.woff) format('woff');
}

However, when I run the app, Firebug returns the following error:

但是,当我运行该应用程序时,Firebug 返回以下错误:

"NetworkError: 404 Not Found - http://localhost:60194/Public/fonts/NuvoWeb-Medi.woff"

“网络错误:404 未找到 - http://localhost:60194/Public/fonts/NuvoWeb-Medi.woff

Please advise as to what I am missing in order to get this to work.

请告知我缺少什么才能使其正常工作。

回答by Shawn de Wet

Found the solution here...

这里找到了解决方案......

The problem is that IIS doesn't know how to serve these new files unless we tell it how. This can be easily done in the web.config's in the web.config's <system.webServer>section by adding the following snippet:

问题是 IIS 不知道如何提供这些新文件,除非我们告诉它如何。这可以<system.webServer>通过添加以下代码段在 web.config部分的 web.config 中轻松完成:

<staticContent>
    <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
    <mimeMap fileExtension=".m4v" mimeType="video/m4v" />
    <mimeMap fileExtension=".ogg" mimeType="video/ogg" />
    <mimeMap fileExtension=".ogv" mimeType="video/ogg" />
    <mimeMap fileExtension=".webm" mimeType="video/webm" />
    <mimeMap fileExtension=".oga" mimeType="audio/ogg" />
    <mimeMap fileExtension=".spx" mimeType="audio/ogg" />
    <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
    <mimeMap fileExtension=".svgz" mimeType="image/svg+xml" />
    <remove fileExtension=".eot" />
    <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
    <mimeMap fileExtension=".otf" mimeType="font/otf" />
    <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
</staticContent>

Note that some of these extensions may already be handled in IIS (for me, .svg was fine). You either need to remove those maps from this section, or include additional <remove>lines like the one for .eot.

请注意,其中一些扩展名可能已经在 IIS 中处理(对我来说,.svg 很好)。您要么需要从此部分中删除这些地图,要么包含其他<remove>行,例如 .eot 的行。

回答by Amrik Singh

Register the MIME type in web.configas follows:

注册 MIME 类型web.config如下:

<system.webServer>
    <staticContent>
      <remove fileExtension=".eot" />
      <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
    </staticContent>
</system.webServer>

This solves the problem.

这解决了问题。

回答by ShibinRagh

public folder(css here) ---> font folder (font here -NuvoWeb-Medi.eot)

公共文件夹(这里的css)--->字体文件夹(这里的字体-NuvoWeb-Medi.eot)

@font-face 
{
    font-family: 'NuvoWeb';
    src: url(fonts/NuvoWeb-Medi.eot);
}

you were missed quotation symbol font-family: 'NuvoWeb';

你错过了引号 font-family: 'NuvoWeb';