css - 使用 css 嵌入字体

标签 css fonts

我正在尝试使用下面的 CSS 导入字体,它在 Firefox 和 IE 中有效,但在 Chrome 中不支持。你能帮我让它也能在 Chrome 中运行吗?

@font-face {
    font-family: "Fontin-Bold";
    src: url(fonts/Fontin-Bold.ttf);
    src: url(fonts/Fontin-Bold.eot);
}

最佳答案

不同的浏览器有不同的需求,字体也不异常(exception)。这是一个完整的例子:

CSS

@font-face {
    font-family: 'UbuntuBold';
    src: url('ubuntu-bold-webfont.eot');
    src: url('ubuntu-bold-webfont.eot?#iefix') format('embedded-opentype'),
         url('ubuntu-bold-webfont.woff') format('woff'),
         url('ubuntu-bold-webfont.ttf') format('truetype'),
         url('ubuntu-bold-webfont.svg#UbuntuBold') format('svg');
    font-weight: normal;
    font-style: normal;

}

你最好使用像这样的字体生成器:Font Squirrel

此外,您需要在您的字体文件夹中设置一个.htaccess,并具有以下类型:

AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf

已编辑:

为了更好地解释不同的字体格式 VS 不同的浏览器:

  • Firefox 和 Safari 支持 TTF 或 OTF 格式;
  • Internet Explorer 支持 EOT 格式;
  • Firefox 3.6 支持新的 WOFF(网络字体的新格式提案 文件);
  • Google Chrome 和 iPhone 的 Safari 允许在 @字体脸;

关于css - 使用 css 嵌入字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10429030/

相关文章:

css @media screen 不能完全工作

fonts - 将报告导出为 PDF 时更改字体

html - 增加表格 1 个单元格的字体大小

css - 如何禁用或覆盖网页中默认从 svg 继承的字体

html - 在菜单栏中居中 p 元素和 div

css - 用 div 填充额外的空间

css - 如何从 Angular 组件中访问本地 CSS 类名

android - 字体未在 ionic 3 应用程序的 android 设备上应用

android - 如何使用支持库 26 在 AlertDialog 中设置自定义字体

jquery - 简单的 JQuery 游戏 - 如何知道两辆汽车 (divs) 何时相遇?