CSS 在 HTML 电子邮件中

CSS in HTML Email

我需要更新一个旧的电子邮件模板。在 4-5 年前的旧模板中,我发现了类似

的内容
<table align="center" border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" class="bodyTable">

现在我不确定他们为什么使用那些语法,只是因为它很旧,还是有任何其他与邮件模板相关的原因?我可以毫无顾虑地将它们更改为:

<table style="text-align:center;border:0;height:100%; width:100%" class="bodyTable">

如果没有,有人可以向我解释为什么吗?

它是,或者至少是,HTML 电子邮件的推荐样式。例如,Smash Magazine 建议 "HTML attributes instead of CSS"。虽然 CSS 支持正在逐步改进,但没有通用的 HTML 电子邮件标准,因此每个电子邮件客户端都支持自己的 HTML/CSS 子集。因此,建议电子邮件设计者 'think 99' 或 post-process 使用特殊 inlining/downgrading 工具的电子邮件模板,例如 http://premailer.dialect.ca (and a few others).

我会说 CSS 多年来一直得到主要电子邮件客户端的良好支持,但是,说在 2011 年,我发现 Whosebug 偶尔会抱怨 gmail.com 剥离样式属性 HTML email in Gmail - CSS style attribute removed .

所以我猜作者选择了玩存档。公司甚至关心受困于有些过时软件的用户的情况并不少见。

根据this list, the major and current email clients support the style attribute well. Still, there is always a risk that a particular tag, attribute, or their combination are not supported by a less know email client, sometimes due to a bug or a corner case, as you can see in a relatively recent post regarding Spark client HTML Email formatting stripped out