我正在制作HTML邮件(HTML Email),我收到的设计中包含自定义字体。如何在我的HTML邮件中使用自定义字体?
谢谢提前。
我正在制作HTML邮件(HTML Email),我收到的设计中包含自定义字体。如何在我的HTML邮件中使用自定义字体?
谢谢提前。
首先,以下电子邮件客户端目前支持Web字体:
(例如,在Gmail Web、Yahoo或新版本的Windows Outlook中无法显示自定义Web字体)
步骤1:如果字体已经托管在像Google Fonts这样的服务中,可以在HTML的<head>
部分引用它,如下所示:
<!-- Desktop Outlook chokes on web font references and defaults to Times New Roman, so we force a safe fallback font. -->
<!--[if mso]>
<style>
* {
font-family: sans-serif !important;
}
</style>
<![endif]-->
<!-- All other clients get the webfont reference; some will render the font and others will silently fail to the fallbacks. -->
<!--[if !mso]><!-->
<link href='https://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'>
<!--<![endif]-->
或者你可以使用@import方法。
<style>
@media screen {
@import url('https://fonts.googleapis.com/css?family=Roboto');
}
</style>
Outlook不支持Web字体,对于这个引用会出现问题,因此将其包装在@media
标签中将使Outlook完全忽略它。
@media screen {
@font-face {
font-family: {font-name};
src: url({http://www.website.com/font-url}) format('woff'),
url({http://www.website.com/font-url}) format('truetype');
font-weight: normal;
font-style: normal;
}
}
注意:如果您想深入了解如何在电子邮件中引用Web字体,请查看Litmus的这篇文章。
font-family: 'Roboto', 'fallback font 1', 'fallback font 2', sans-serif;