为 Gmail 设置 HTML 电子邮件样式
我正在生成使用内部样式表的 html 电子邮件,即
I'm generating a html email that uses an internal stylesheet, i.e.
<!doctype html>
<html>
<head>
<style type="text/css">
h2.foo {color: red}
</style>
</head>
<body>
<h2 class="foo">Email content here</foo>
</body>
</html>
在 Gmail 中查看时,内部样式表中的所有样式似乎都被忽略了.似乎 Gmail 忽略了除内联规则之外的所有样式,例如
When viewed in Gmail it seems all the styles in the internal stylesheet are ignored. It seems Gmail ignores all styles other than inline rules, e.g.
<h2 style="color: red">Email content here</foo>
这是我在使用 Gmail 查看时设置 HTML 电子邮件样式的唯一选择吗?
Is this my only option for styling HTML emails when viewed with Gmail?
推荐答案
截至 2016 年 9 月 30 日,此处的答案已过时.Gmail 目前是 推出对 style
标签的支持>head,以及媒体查询.如果您只关心 Gmail,那么您可以像现代开发人员一样安全地使用课程!
The answers here are outdated, as of today Sep 30 2016. Gmail is currently rolling out support for the style
tag in the head
, as well as media queries. If Gmail is your only concern, you're safe to use classes like a modern developer!
作为参考,您可以查看官方 gmail CSS 文档强>.
For reference, you can check the official gmail CSS docs.
附带说明,Gmail 是唯一不支持 style
(参考,直到它们更新为止).这意味着您可以几乎安全地停止将样式内联.一些比较模糊的客户可能仍然需要它们.
As a side note, Gmail was the only major client that didn't support style
(reference, until they update anyway). That means you can almost safely stop putting styles inline. Some of the more obscure clients may still need them.
相关文章