将外部 CSS 转换为 Rails 中邮件的内联 CSS
我正在尝试创建一个应用程序,该应用程序将发送样式繁重的电子邮件,并要求客户端工作(Google Gmail 除外)。我研究了这个问题,看起来 Gmail 删除了外部文件中的 CSS 或嵌套在“style”标签中的 CSS。是否存在将样式从外部文件移动到内联的简单方法?
需要的东西:
<style>
.wide { width: 100px; }
.cell { display: block; }
</style>
<span class="wide cell">Sample</span>
并将其转换为:
<div class="wide cell" style="width: 100px; display: block;">Sample</div>
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以查看以下一些精华:
我在写这个答案时还没有获胜者,但 premailer 似乎是最新的。
Here are couple of gems you can check out:
I have no winner at the time writing this answer but premailer seems to be most up-to-date.
添加了
预邮件程序
:Added
premailer
:您的推理只有一个问题......许多样式,甚至内联样式,都不被支持。
以下是电子邮件支持的内容的参考
在您的示例中,您使用display: 标记,Outlook 07+ 不支持
我的公司每天发送数千封电子邮件我经常参与构建它们。在实践中,内联样式是有效的,但它并不像只内联所有内容那么简单并且它会起作用。您必须非常小心您使用的内容以及如何使用它。我已经开始,用纯 HTML 和表格布局完成几乎所有事情。这基本上是我发现的几乎 100% 时间都能正常工作的唯一方法。
如果您要将此功能构建到一个会得到大量使用的应用程序中,我还强烈建议在 Email 中构建通过他们的 API 访问 Acid。虽然您可以编写出质量非常好的输出,但 Microsoft 无疑会找到某种方法使您的有效代码不起作用。 Acid 上的电子邮件将使用微软当时使用的任何疯狂方式进行渲染,以向您展示您的电子邮件是否有效。这是纯粹的天才,对于那些认真发送大量电子邮件的人来说是必需的。不,我不为公司工作......
There's just one problem with your reasoning.....many styles, even inline, aren't supported.
Here's a reference for what is supported in email
In your example, you use the display: tag, which isn't supported by Outlook 07+
My company sends out thousands of emails a day and I often have a hand in building them. In practice, inline styles work, but it's not as simple as just in-lining everything and it will work. You have to be extremely careful about what you use and how you use it. I've resorted to my beginnings, doing nearly everything in pure HTML with tables for layouts. It's basically the only way I've found to get things to work nearly 100% of the time.
If you're building this functionality into an app that's going to get a lot of use, I'd also strongly recommend building in Email on Acid via their API. While you can code a very good quality output, Microsoft will no doubt find some way to make your valid code not work. Email on Acid will render using whatever madness Microsoft is using at the time to show you if your email works. It's pure genius and required use for those who are serious about sending a ton of emails. And no, I don't work for the company....