html - @font-face 不加载自定义字体

标签 html css fonts font-face

我正在尝试使用已上传到文件系统中的字体文件夹中的自定义字体 (.oft)。

我已经在 CSS 中声明了以下字体:

@font-face {
    font-family: '400'; /*a name to be used later*/
    src: url('../font/400ml-Regular.otf'); /*URL to font*/
}

并用 :

调用它
.intro .slogan {
    text-align: center;
    font-family: '400';
}

我的 index.html 页面在根文件夹 (var/www/html) 中,css 和字体分别在/var/www/html/css 和/var/www/html/font 中(所以我认为src 中的 '..' 是正确的)。我还在 .htaccess 中添加了以下内容

AddType font/otf .otf

但我仍然无法在开发人员工具中看到它加载。

有人有什么建议吗?

最佳答案

要让@font-face 在不同的浏览器和 OP 上工作,你需要像这样

@font-face {
  font-family: '400';
  src: url('400ml-Regular.eot'); /* IE9 Compat Modes */
  src: url('400ml-Regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
       url('400ml-Regular.woff') format('woff'), /* Modern Browsers */
       url('400ml-Regular.ttf')  format('truetype'), /* Safari, Android, iOS */
       url('400ml-Regular.svg#svgFontName') format('svg'); /* Legacy iOS */
}

使用字体生成器制作不同的字体格式。尝试 fontsquirel或类似 :)

关于html - @font-face 不加载自定义字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26716593/

相关文章:

javascript - 单元格中忽略的 dgrid 空白 css 属性

html - "%"IE无法识别

unicode - 字符集、语言环境、字体和代码页?

java - 使用强制等宽终端字体 Java AWT

javascript - 使用 jQuery 比较 2 个输入字段的值

javascript - jQuery 加载多个 ul 列表的前 3 个元素

css - IE 中不需要的 (img) 侧边距

image - 渐近线 : resizing the picture (including pen widths and font sizes)

jquery - 动态创建的 DOM 元素不增加 div 大小

html - 如何将 "text-align"设置为其默认值(禁用 "text-align"继承)