我正在为电子邮件时事通讯设计一个HTML模板。我了解到许多电子邮件客户端忽略了链接的样式表,而其他许多客户端(包括Gmail)完全忽略了CSS块声明。内联样式属性是我唯一的选择吗?样式化HTML电子邮件的最佳实践是什么?
当前回答
“胆小鬼。我将使用样式表制作一个HTML页面,然后使用jQuery将样式表应用到每个元素的样式attr。就像这样:
var styleAttributes = ['color','font-size']; // all the attributes you've applied in your stylesheet
for (i in styleAttributes) {
$('body *').css(styleAttributes[i],function () {
$(this).css(styleAttributes[i]);
});
}
然后复制DOM并在电子邮件中使用它。
其他回答
Campaign Monitor有一个很好的支持矩阵,详细说明在各种邮件客户端中支持什么,不支持什么。
您可以使用Litmus这样的服务来查看电子邮件如何在多个客户端之间出现,以及它们是否被过滤器捕获等等。
除了这里发布的答案,一定要阅读这篇文章:
http://24ways.org/2009/rock-solid-html-emails
邮件黑猩猩有一篇很好的文章,告诉你什么是不该做的。(我知道这听起来和你想要的完全相反)
http://kb.mailchimp.com/article/common-html-email-coding-mistakes
总的来说,你所学到的所有不好的网页设计实践似乎都是html电子邮件的唯一选择。
基本原则是:
为图像提供绝对路径(例如。 https://stackoverflow.com/random-image.png) 使用表格进行布局(从未想过 我建议这样做!) 使用内联样式(和老式css) 而且,最多2.1,盒影 不会工作,例如;))
只要在尽可能多的电子邮件客户端中进行测试,或者像上面其他人建议的那样使用Litmus !(credit to Jim)
编辑:
邮件黑猩猩做了一个伟大的工作,使这个工具可用的社区。
它应用你的CSS类到你的html元素内联为你!
我曾经打过HTML电子邮件之战。以下是我的一些关于如何在电子邮件客户端之间实现最大兼容性的设计技巧。
Inline styles are you best friend. Absolutely don't link style sheets and do not use a <style> tag (GMail, for example, strips that tag and all it's contents). Against your better judgement, use and abuse tables. <div>s just won't cut it (especially in Outlook). Don't use background images, they're spotty and will annoy you. Remember that some email clients will automatically transform typed out hyperlinks into links (if you don't anchor <a> them yourself). This can sometimes achieve negative effects (say if you're putting a style on each of the hyperlinks to appear a different color). Be careful hyperlinking an actual link with something different. For example, don't type out http://www.google.com and then link it to https://gmail.com/. Some clients will flag the message as Spam or Junk. Save your images in as few colors as possible to save on size. If possible, embed your images in your email. The email won't have to reach out to an external web server to download them and they won't appear as attachments to the email.
最后,测试,测试,测试!每个电子邮件客户端都与浏览器的工作方式不同。
关于HTML电子邮件,我最后总是回到CampaignMonitor的CSS指南。
由于他们的业务完全围绕电子邮件传递,所以他们比任何人都了解自己的业务
推荐文章
- 使伸缩项目正确浮动
- 如何取消最大高度?
- 形式内联内的形式水平在twitter bootstrap?
- 自定义元素在HTML5中有效吗?
- 如何选择在最后一个子元素之前的元素?
- 如何触发自动填充在谷歌Chrome?
- CSS变换,锯齿边缘在铬
- 创建圈div比使用图像更容易的方法?
- 强迫孩子服从父母的弯曲边界在CSS
- 为什么Chrome浏览器不正确地确定页面是在不同的语言,并提供翻译?
- 在CSS中@apply是什么?
- 在网页上用鼠标模拟震颤(例如帕金森病)?
- Bootstrap抛出Uncaught错误:Bootstrap的JavaScript需要jQuery
- 如何改变文本区域的边框颜色:焦点
- 我如何设置背景颜色为文本的宽度,而不是整个元素的宽度,使用CSS?