是否有可能像CSS一样将字体文件嵌入到html中? [英] Is it possible to embed font files into html just like css?

查看:428
本文介绍了是否有可能像CSS一样将字体文件嵌入到html中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我从事的项目中,我需要生成一个一页HTML文件,其中包含其中的所有内容(JavaScript代码,CSS,图像等).因此,不应有外部参考.

In a project I work on, I need to generate a one page HTML file which contains everything inside it (JavaScript code, CSS, Images, etc.). So, there should be no outside references.

我还计划使用Bootstrap,但是我不确定是否可以像CSS一样将字体文件嵌入HTML.

I am also planning to use Bootstrap but I am not sure if it is possible to embed font files inside HTML just like CSS.

有什么主意吗?

推荐答案

是的,实际上是可行的.您可以将字体嵌入为base64编码的字体,如下所示:

Yes, that's actually possible. You can embed the font as a base64 encoded font like this:

@font-face{
    font-family: FontName;
    src: url(data:font/ttf;base64,THESTRING… ) format('truetype');
}

但是不建议这样做,因为base64字符串可能会变得很大而导致性能问题.

But it's not advisable as the base64 string can get rather big and cause performance issues.

这篇关于是否有可能像CSS一样将字体文件嵌入到html中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆