有什么方法可以将块 style/CSS 转换为内联 CSS?

Any way to transform a block style/CSS to inline CSS?

我正在编写一个 HTML/CSS 电子邮件模板,用于触发 Gmail 和其他邮件。但是,Gmail 不加载 <style> 块,所以我必须使用内联 'style' 属性来使其工作。

为了说明问题:

<style>
    .center {
        text-align:center;
    }
</style>
<a class="center"> text </a>

转换为:

<a class="center" style="text-align:center;"> text </a>

这里有人知道更好的方法或程序吗?

有专为该工作设计的网络应用程序。

Converts CSS rules into inline style attributes

https://inlinestyler.torchbox.com/

Premailer 是生成内联样式和为电子邮件准备代码的好工具。

您甚至可以使用 grunt or gulp.

将其集成到您的任务运行程序中