有没有办法将字体添加到资源文件夹并加载它为HTML?

时间:2016-11-08 21:24:44

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

我希望我的文字在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>

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

2 个答案:

答案 0 :(得分:1)

使用:代替或=

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

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

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

答案 1 :(得分:0)

您仍然需要url()

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