我有一个自定义字体 .ttf 和 .otf 文件,我已将它们添加到我的 mvc 元素中的字体文件夹中。我如何从 CSS 中调用它们?看到一些文章谈论打开字体管理器或 html 设计器,但我看不到任何东西来嵌入它们以便它们在所有浏览器上工作?
谢谢
最佳答案
您已经将自定义字体添加到 Visual Studio 中的字体文件夹中。
现在您所要做的就是在@font-face 规则中指向您的字体:
@font-face {
font-family: "MyCustomFont.ttf";
font-style: normal;
src: url(../fonts/MyCustomFont.ttf); /*if IE */
src: local("MyCustomFont"), url("../fonts/MyCustomFont.ttf") format("truetype"); /* non-IE */
}
如果您需要其他字体,只需添加另一个@font-face 规则
@font-face {
font-family: "MyCustomFont2.otf";
font-style: normal;
src: url(../fonts/MyCustomFont2.otf); /*if IE */
src: local("MyCustomFont2"), url("../fonts/MyCustomFont2.otf") format("truetype"); /* non-IE */
}
这种方法适用于所有浏览器。
来源: https://forums.asp.net/t/1589195.aspx?Adding+a+font+to+use+in+visual+studio
关于css - 在 visual studio 2015 中嵌入字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42720000/