【问题标题】:@font-face embeded in aspx file not working@font-face 嵌入在 aspx 文件中不起作用
【发布时间】:2015-04-19 17:43:26
【问题描述】:

我正在尝试在我的网站中使用一些有趣的字体。但不知何故,字体没有被加载或由于某种原因无法正常工作。

我有一个母版页,其中存在 2 个<asp:ContentPlaceHolder> 标签。一个在 head 部分用于类似用途,例如使用 external fonts ,另一个在 body 部分 <asp:ContentPlaceHolder>

我尝试了两件事:

1) 提供存储在我的视觉工作室中的字体的网址。

2) 其他给出我的文件系统的 url。

这是我的 HTML 文件:

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <style>
        @font-face{
            font-family:Junction;
            src : url("http:localhost:63183/fonts/Junction.otf") format('opentype');
        }
        @font-face{
            font-family:chunkfive;
            font-weight:bold;
            src : url("f:\practicals7th sem\project docs\templates\temp1\chunkfive.otf") format('opentype');
        }

    </style>
</asp:Content>

这是我的正文部分内容:

<div style="text-align: center; font-family:'Junction.otf' ; font-size: 20px; color: #db2828">
                            <%# Eval("Name") %>

【问题讨论】:

标签: html css asp.net iis fonts


【解决方案1】:

您需要在 IIS 中设置 MimeTypes:

<system.webServer>
    <staticContent>
        <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
        <mimeMap fileExtension=".ttf" mimeType="application/octet-stream" />
        <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
        <mimeMap fileExtension=".woff" mimeType="application/x-woff" />
        <mimeMap fileExtension=".otf" mimeType="font/opentype" />
    </staticContent>
</system.webServer>

然后您可以使用字体的相对路径,即

 @font-face{
            font-family:Junction;
            src : url("/fonts/Junction.otf") format('opentype');
        }
        @font-face{
            font-family:chunkfive;
            font-weight:bold;
            src : url("/fonts/chunkfive.otf") format('opentype');
        }

【讨论】:

  • 添加这个导致我渲染的 HTML 看起来像一个骨架。我不知道为什么,但这不起作用。
  • 你有/fonts文件夹中的文件吗?你有 404 吗?
  • 是的,我在 Visual Studio 的 Server Explorer 中有一个 /Fonts 文件夹。我应该在哪里期待 404?
  • @AbhishekGhosh 更新 mime 类型。请重试。
  • 请检查我添加的屏幕截图。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-19
  • 2013-01-04
  • 2014-09-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多