【问题标题】:is there a way to add a font into assets folder and load it for html?有没有办法将字体添加到资产文件夹并为 html 加载它?
【发布时间】:2017-03-22 15:44:36
【问题描述】:

我希望我的文本在web view 中看起来更好,但是当我尝试为其加载字体时,它不会改变。 根据一些问题thisthis 我找到了这段代码:

<style type="text/css">
@font-face {
font-family: "My Custom Font";
src: url(http://www.example.org/mycustomfont.ttf) format("truetype");
}
p.customfont { 
font-family: "My Custom Font", Verdana, Tahoma;
}
</style>
<p class="customfont">Hello world!</p>

我试过这个从资产加载它:

<style type=text/css>
@font-face {
font-family: "ROYA";
src="Roya.ttf";
}
p.customfont { 
font-family: "ROYA", Verdana, Tahoma;
}
<p class="ROYA">Hello world!</p>

但它不起作用。我该怎么办?

【问题讨论】:

    标签: html css fonts font-face custom-font


    【解决方案1】:

    你仍然需要url()

    @font-face{
      font-family: "ROYA";
      src: url("Roya.ttf") format("truetype")
    }
    

    【讨论】:

    • @MohammadRezaMajidPour 为什么不呢?您的网络选项卡中有什么? Roya.ttf 在 CSS 的相对路径中吗?
    • 我不知道什么时候用 html 查看器加载它与设备字体相同
    • @MohammadRezaMajidPour 如果您无法回答有关此问题的基本问题,我们无法为您提供帮助。你后来甚至使用字体设置字体系列吗?字体下载了吗?你把字体放在哪里了?我无法读懂你的想法,我不知道你把字体放在哪里。使用浏览器的开发者工具。
    • 我把字体放在与html同名的文件夹中
    • 也许是关于风格
    【解决方案2】:

    使用 : 或 =

    @font-face{
      font-family: "ROYA";
      src: url("Roya.ttf") format("truetype");
    }
    

    并在下一个代码块上更改类名

    p.ROYA { 
    font-family: "ROYA", Verdana, Tahoma;
    }
    <p class="ROYA">Hello world!</p>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-05
      • 1970-01-01
      • 2017-11-04
      • 2016-03-24
      • 2015-07-02
      • 1970-01-01
      • 2020-01-08
      相关资源
      最近更新 更多