我们还需要在 HTML 电子邮件中使用 <font> 标签吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8012799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:23:39  来源:igfitidea点击:

Do we still need to use <font> tags in HTML emails?

htmlemailhtml-email

提问by punkrockbuddyholly

I'm taking over from someone who builds our HTML emails and the templates are filled with font tags. Is this really necessary? I know CSS support isn't great in emails, but if I set an inline style for text on the container <td>like this...

我正在接替构建我们的 HTML 电子邮件的人,并且模板中充满了字体标签。这真的有必要吗?我知道 CSS 支持在电子邮件中不是很好,但是如果我<td>像这样为容器上的文本设置内联样式......

<td style="font-family:Arial, Helvetica;color:#555555;font-size:12px">

...then surely this will work across the majority of email clients. From the tests I've performed this seems to be the case, and this articleseems to confirm this.

...那么这肯定适用于大多数电子邮件客户端。从我执行的测试来看,情况似乎是这样,这篇文章似乎证实了这一点。

Anyone have any input as to whether <font>tags are really necessary in HTML emails?

任何人都<font>对 HTML 电子邮件中是否真的需要标签有任何意见?

采纳答案by Doozer Blake

Your assumption is correct. They're unnecessary. Also, technically the <font>tag was deprecated starting with HTML 4, so you might as well remove it for that sake alone.

你的假设是正确的。它们是不必要的。此外,从技术上讲,<font>从 HTML 4 开始不推荐使用该标签,因此您最好仅出于这个原因将其删除。

If you needed inline css styles on specific text, you would be better of using an inline-styled <span>tag than a <font>tag.

如果您需要在特定文本上使用内联 css 样式,则最好使用内联样式<span>标签而不是<font>标签。

Campaign Monitor has a great and up-to-date resource on current CSS support in emails.

Campaign Monitor 拥有关于电子邮件中当前CSS 支持的大量最新资源。

回答by Synchro

Sadly the accepted answer is not true, and even hideous things like @MrMisterMan's post are still de rigeur.

可悲的是,接受的答案不是真的,甚至像@MrMisterMan 的帖子这样的可怕的东西仍然是正常的

Deprecated as it may be, the font tag is stillthe only thing that works universally across pretty much all email clients, old and new. Bear in mind that email is not the web and it's still positively antediluvian. Some email services do unspeakable things; I've encountered one that blindly stripped all HTML tags (ignoring provided plain-text versions), converted linked images to attachments, resulting in an unreadable mess. Even contemplating having inline styles working in the face of such vandalism is truly wishful.

尽管可能已被弃用,但字体标签仍然是唯一可以在几乎所有新旧电子邮件客户端上通用的东西。请记住,电子邮件不是网络,它仍然是非常古老的。一些电子邮件服务做着不可描述的事情;我遇到过一种盲目剥离所有 HTML 标签(忽略提供的纯文本版本),将链接的图像转换为附件,导致无法阅读的混乱情况。即使考虑在面对这种破坏行为时使用内联样式也确实是一厢情愿。

Want to know where the big hole is? Hotmail. hotmail, live.com and outlook.com strip or replace inline styles, yes, even in 2013. Blame Microsoft: hotmail, live, outlook.com and outlook have all got considerably worse in the last few years (e.g. floats were dropped from outlook.com 6 months ago; outlook dropped background images in 2007 and they've not been seen since).

想知道大洞在哪里吗?热信。hotmail、live.com 和 outlook.com 删除或替换内联样式,是的,即使在 2013 年也是如此。 责怪微软:hotmail、live、outlook.com 和 Outlook 在过去几年中都变得更糟(例如,浮动从 Outlook 中删除.com 6 个月前;Outlook 在 2007 年放弃了背景图片,此后就再也没有出现过)。

Inline styles work in Gmail, but it strips anything outside the body tag. Some corporate mail filters (like BlackSpider/WebSense) do exactly the opposite, so if you want to be completely sure about your styling, you need to put a style tag in the head tag, another copy of it within the body (invalid, but it works), the same styles inline (look at the premailerproject), and finally the same styling using font tags. Yes, it's insane, but no amount of wishing is going to make the problem go away. You can of course drop some of these, but by doing so you're implicitly accepting that it's not going to look the same in some places. You need to look at your audience - a new mobile music site can probably get away with it, but a corporate pension provider probably needs to be living in 2003 font-tag land.

内联样式在 Gmail 中有效,但它会去除正文标签之外的任何内容。一些公司邮件过滤器(如 BlackSpider/WebSense)做的恰恰相反,所以如果你想完全确定你的样式,你需要在 head 标签中放置一个样式标签,在正文中再放一个它的副本(无效,但它有效),相同的样式内联(查看premailer项目),最后使用字体标签的相同样式。是的,这很疯狂,但再多的愿望也无法解决问题。您当然可以删除其中的一些,但是通过这样做,您隐含地接受了它在某些地方看起来不一样。你需要看看你的听众——一个新的移动音乐网站可能会侥幸逃脱,但企业养老金提供者可能需要生活在 2003 年的字体标签领域。

Fortunately Apple Mail, iOS mail and iCloud all have vastly superior HTML handling (as that Campaign Monitor table shows, as does the email standards project). With the majority of mobile reading using some flavour of WebKit, rendering on mobile is generally much more consistent (and mostly better) than on desktops.

幸运的是,Apple Mail、iOS 邮件和 iCloud 都具有非常出色的 HTML 处理能力(如 Campaign Monitor 表所示,电子邮件标准项目也是如此)。由于大多数移动阅读使用某种风格的 WebKit,因此在移动设备上的渲染通常比在台式机上更加一致(并且大多更好)。

You could simply say that it's not worth the effort (what the accepted answer is effectively saying) - anyone using crappy mail readers clearly doesn't care that much what their email looks like, but that doesn't mean that your styling isn't going to break.

您可以简单地说这是不值得的(公认的答案实际上是在说) - 任何使用蹩脚邮件阅读器的人显然都不太在意他们的电子邮件是什么样子,但这并不意味着您的样式不是要休息了。