html - 条件注释不起作用

标签 html css conditional-statements

我正在构建一个需要通过@font-face 使用自定义字体的网站。 IE 仅在我使用 .eot 扩展名时显示;仅当我使用 .ttf 扩展名时才能使用其他浏览器。

我无法弄清楚如何使用条件注释来同时使用这两者 - 尽管我已经尝试了网络上的大量建议......但对我来说没有任何效果。

基本上,我有:

<style>
@font-face{
font-family: Square;
src: url(/wpadmin/fonts/Square.ttf);
}

@font-face{
font-family: Square_IE;
src: url(/wpadmin/fonts/Square.eot);
}

</style>

<!--[if !IE]><!-->
<style>
#Title{
font-family:Square;
}
</style>
<!--<![endif]-->

<!--[if IE]><!-->
<style>
#Title{
font-family:Square_IE;
}
</style>
<!--<![endif]-->

这里的字体只能在 IE 中正确显示 - 不能在其他浏览器中显示。如果我删除 [if IE] 语句,它就会在其他浏览器中正确显示。

我尝试了很多变体,包括 html 正文中的条件语句。

我做错了什么?

最佳答案

条件注释在 IE 11 中不起作用,但这也不是标准方法。您不需要不同的字体名称,您只需为所有引用同一个名称的字体文件的跨浏览器列表执行此操作即可。

/* declare all the files - browser will use the best it understands */

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


/* now just reference the one name */

#Title {
  font-family:Square;
}

关于html - 条件注释不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29429984/

相关文章:

mysql - 如何编写条件 SQL 语句

html - 无法清除 Ionic 中输入文本字段中的文本

javascript - 更改 Vimeo 播放器背景颜色

f# - 有条件地在 F# 中的正向管道链中应用过滤器?

c - 使用位运算

jQuery 克隆 |

jquery - 为什么我不能从元素中删除内联样式

html - 我可以在 Unity 窗口上叠加 HTML 吗?

css - 如何将 div 与视口(viewport)垂直对齐,同时将其与文档水平对齐?

javascript - 如何在 Angular js 中使用 $scope 变量将类分配给元素