【问题标题】:CSS font stack substitution issues in Outlook when using Google Webfonts使用 Google Webfonts 时 Outlook 中的 CSS 字体堆栈替换问题
【发布时间】:2013-08-27 17:10:32
【问题描述】:

在 HTML 电子邮件中使用 Google Webfonts 我在 Outlook(2007、2010 等)中遇到了在合并 webfonts 之前没有出现的字体替换问题。它会忽略字体堆栈并直接转到 Times。

尽管使用了内联后备字体堆栈,但仍会发生这种情况。

我注意到以前在这里发布过的类似问题,但只是作为一般问题,与网络字体的使用无关。以前所有的字体后备都可以正常工作。我正在使用 Litmus 进行电子邮件测试。

有谁知道为什么会发生这种情况?

Litmus 链接:https://litmus.com/pub/53a33c7/screenshots

原来在 CSS 中链接的字体是这样的:

<link href='http://fonts.googleapis.com/css?family=Arvo|Droid+Serif:400,700,400italic,700italic|Roboto:300' rel='stylesheet' type='text/css'>

在看到可能的 solution in another answer 后,我也尝试使用 @font-face 和自托管文件,但它不起作用(我也更新了类名):

除了 font-face 尝试的解决方法:

<!--[if !mso]><!--> 

@font-face {
    font-family: 'droid_serif';
    src: url('http://www.suissamesser.com/emails/rsdsa/DroidSerif-webfont.eot');
    src: url('http://www.suissamesser.com/emails/rsdsa/DroidSerif-webfont.eot?#iefix') format('embedded-opentype'),
         url('http://www.suissamesser.com/emails/rsdsa/DroidSerif-webfont.svg#droid_serif') format('svg'),  
         url('http://www.suissamesser.com/emails/rsdsa/DroidSerif-webfont.woff') format('woff'),
         url('http://www.suissamesser.com/emails/rsdsa/DroidSerif-webfont.ttf') format('truetype');

    font-weight: normal;
    font-style: normal;

}
<!--<![endif]-->

Outlook 特定的覆盖 CSS 似乎有效,但存在优先级问题。我不相信 Outlook 能够识别 !important 声明,因此我一直在努力进行更具体的选择。但是,我仍然不明白为什么会发生这种情况以及是否有更简单的解决方法。

Outlook 字体覆盖摘录:

    <!--[if gte mso 9]>
    <style>
        /* Target Outlook 2007 and 2010 */

            h1 { font-family: 'Georgia',serif !important; font-weight:normal; }
            h1 a { font-family: 'Georgia',serif !important; font-weight:normal; }
            h2 { font-family: 'Trebuchet MS',arial, helvetica, sans-serif; font-weight:normal; }
            h3 { font-family: 'Trebuchet MS',arial, helvetica, sans-serif; }
            .cover,img.cover,a.cover {
                display: block;
                visibility: visible;

                td { font-family: 'Trebuchet MS',arial, helvetica, sans-serif; } 

                .droid { font-family: 'Georgia', serif; }
}
    </style>
    <![endif]-->

有问题的代码示例:

<td height="30" colspan="3" align="left" valign="middle" class="featured">
    <h2 style="text-align: left; padding: 0; margin: 0; color: #00799f; font-family: 'Roboto',arial, helvetica, sans-serif; font-size: 21px; font-weight: 100; background: none; border-bottom: 1px solid #b1d6e2; text-decoration: none; line-height: 36px; mso-line-height-rule: exactly;">cover story</h2>
</td>

更新:

我已经尝试了答案中的建议,将 webfont 导入代码放在排除 Outlook 的条件标签内,但无济于事。

<!--[if !mso]><!-- -->
@import url(http://www.example.css);
<!--<![endif]-->

<!--[if !mso]><!-- -->
@import url(http://fonts.googleapis.com/css?family=Oxygen);
<!--<![endif]-->

更新二(解决方案):

在提供的所有帮助下,很明显,一些看似很小的问题都可能导致此问题。 font-face 方法似乎比@import 更可取。网络字体名称与本地字体不同可能会导致同样的问题,但这并不是这封特定电子邮件所发生的情况。

我很早就尝试过使用条件代码从 Outlook &lt;!--[if !mso]&gt;&lt;!--&gt; 完全隐藏 webfont 导入代码。

问题是我在 head 部分的 CSS 样式标记中执行此操作。只需将此代码放在其自己的样式标签中,如下所示即可。

我确认它正在工作,因为我能够删除用于检测 Outlook 2007 和更高版本的额外解决方法 CSS 代码,以将 h1、h2 值恢复到标准字体堆栈。

<!--[if !mso]><!-->
<style type="text/css">
@font-face {
    font-family: 'oxygenlight';
    src: url('http://www----/fonts/oxygen-light-webfont.eot');
    src: url('http://www.----/fonts/oxygen-light-webfont.eot?#iefix') format('embedded-opentype'),
         url('http://www.-----/fonts/oxygen-light-webfont.woff') format('woff'),
         url('http://www.-----/fonts/oxygen-light-webfont.ttf') format('truetype'),
         url('http://www.-----/fonts/oxygen-light-webfont.svg#oxygenlightlight') format('svg');
    font-weight: normal;
    font-style: normal;
}
</style>
<!--<![endif]-->

【问题讨论】:

标签: html css outlook html-email


【解决方案1】:

更新:Here is a technique 在所有版本的字体堆栈中调用 webfonts 并回退到字体堆栈 打破的前景

如果不是 Outlook,请尝试声明您的网络字体。 webfont 可能对 Outlook 有问题,因此根本不调用它可能会起作用。值得一试...

编辑:

这个问题有occured before,当您的第一个声明字体用引号引起来时,Outlook 会中断。不幸的是,这似乎是一个不可避免的 Outlook 错误/限制。

【讨论】:

  • 抱歉,澄清一下,我知道是 webfont 导致了这个问题,只是想找到最好的解决方案来让后备工作正常工作。
  • 是的,我建议您使用[if !mso] 内的webfont 链接,这样Outlook 就不必看到它。这比尝试通过变通方法教 Outlook 忽略它更简单
  • 尝试了一些变体,但没有任何运气。将更新问题。不过建议很好。
  • 您是否使用自己的&lt;font&gt; 标签来包装电子邮件中的所有文本部分?您必须在每个表格单元格或字体标签中声明字体。
  • @jsuissa 更新了答案,但不幸的是我认为这不会成功......
【解决方案2】:

要让 Outlook 使用您的字体堆栈,而不是用 Outlook 选择的任何字体替换您的网络字体,请添加一个条件注释,该注释只能由 Outlook 读取,以分配您的字体堆栈备份字体。定义您的网络字体,但不要在条件注释中定义它,因此 Outlook 将忽略网络字体,直接进入它的条件注释并仅显示 Arial。

<style>
        @import url('http://www.yourdomain.com/webfont.css');
</style>

    <!--[if gte mso 9]>
        <style>
            .webfontsubstitute { font-family: arial, sans-serif; }
        </style>
    <![endif]-->

</head>
<body>

    <a href="#" target="_blank" style="font-family:superwebfont,arial,sans-serif;">
    <span class="webfontsubstitute">WEB FONT STYLED TEXT HERE</span></a>

【讨论】:

    【解决方案3】:

    我也遇到过这个问题,刚刚找到了一个非常简单的解决方法。导入网络字体后,@media screen { } 可用于挑选支持媒体查询的客户端,而这些恰好是支持网络字体的客户端。因此,只需在此选择器的内部和外部指定 font-family 声明,您就可以从电子邮件客户端(例如 Outlook)隐藏特定字体,以便显示下一个适当的备用字体,并显示您的网络字体在支持它的客户中很好。

    @import url(http://fonts.googleapis.com/css?family=Open+Sans:300);
    
    .h1 { font-family: 'Arial', 'Helvetica', sans-serif }
    
    @media screen {
        .h1 {
            font-family: Open Sans, 'Arial', 'Helvetica', sans-serif
        }
    }
    

    顺便说一句,Campaign Monitor suggests 在一般的电子邮件中,@import@font-face 要好。

    【讨论】:

      【解决方案4】:

      我记得不久前遇到过类似的问题。最后我认为是@import 引起了问题,我不得不使用不同的方法来拉入字体。

      不要使用@import,而是使用@font-face 方法。

      @font-face {
        font-family: 'Oxygen';
        font-style: normal;
        font-weight: 400;
        src: local('Oxygen'), local('Oxygen-Regular'),     url(http://themes.googleusercontent.com/static/fonts/oxygen/v2/eAWT4YudG0otf3rlsJD6zOvvDin1pK8aKteLpeZ5c0A.woff) format('woff');
      }
      

      然后像往常一样使用字体:

      h1 {
        font-family: 'Oxygen', sans-serif;
      }
      

      【讨论】:

      • 对您的建议不满意,但我认为我们走在正确的轨道上。在电子邮件中发布了带有 Litmus 测试链接的编辑。
      【解决方案5】:

      问题可能是因为您的用户在本地安装了字体版本并且存在冲突。

      尝试@font-face 导入(无论如何这都是 Google WebFonts 的工作方式),只需将 font-family 重命名为不同的名称。

      例如

      @font-face {
          font-family: 'droid_serif';
      

      到:

      @font-face {
          font-family: 'droid_serif_alt';
      

      一定要在你的标记的其余部分反映变化!

      【讨论】:

        【解决方案6】:

        您必须使用“mso-font-alt”作为字体回退(Outlook 2010,2013,2016):

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
           <head>
        
            ....
        
            <style type="text/css">
        
            @font-face {
                font-family: 'droid_serif';
                src: url('http://www.suissamesser.com/emails/rsdsa/DroidSerif-webfont.eot');
                src: url('http://www.suissamesser.com/emails/rsdsa/DroidSerif-webfont.eot?#iefix') format('embedded-opentype'),
                 url('http://www.suissamesser.com/emails/rsdsa/DroidSerif-webfont.svg#droid_serif') format('svg'),  
                 url('http://www.suissamesser.com/emails/rsdsa/DroidSerif-webfont.woff') format('woff'),
                 url('http://www.suissamesser.com/emails/rsdsa/DroidSerif-webfont.ttf') format('truetype');
        
                font-weight: normal;
                font-style: normal;
                mso-font-alt: 'Arial';
            }
        
            ...
        
            </style>
        </head>
        

        另一个覆盖自定义 css 声明的技巧:

        <!--[if mso]>
            <style> 
              body,table tr,table td,table th,a,span,table.MsoNormalTable { 
                font-family: 'Arial', 'Helvetica', 'sans-serif' !important;  
              }
              .custom-headline{
                  font-family: 'Times New Roman', 'serif' !important;
              }
            </style>
        <![endif]-->
        

        也请看一下:https://litmus.com/community/code/36-outlook-and-fallback-fonts

        【讨论】:

        • 对这是否有效有任何反馈吗?哪些版本的 Outlook 支持它?如果它有效,那就太棒了,但没有 cmets 或 upvotes,我很犹豫要不要尝试。
        • 这仍然有效,对于 OUTlook 2019 也是如此。我专门指的是 mso-font-alt,但第二个技巧应该仍然有效。我一直使用第一个,因为它很简单。
        猜你喜欢
        • 2015-05-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-07
        • 1970-01-01
        • 2011-03-17
        • 1970-01-01
        • 2015-03-03
        相关资源
        最近更新 更多