将引用的样式表动态添加到内联样式 [英] Dynamically add referenced stylesheet to inline styles

查看:145
本文介绍了将引用的样式表动态添加到内联样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景

我已经创建了一个页面,客户端可以构建自己的页面,日历,小部件,文章等。

I have created a page where the client can build their own page, calendars, widgets, articles etc. I have created a second Dynamic builder page where they can build their own newsletters.

问题

所有我的CSS都被引用,因为邮件程序非常有限,我必须添加所有样式 inline

All my css is referenced with classes, because mailers are very limited I have to add all styles inline.

问题

有没有可以运行的脚本来通过类获取所有引用的样式,并将其添加到相关元素/标签内联样式?

Is there a script I can run to grab all referenced styles via class, and add it to the relevant elements/tags inline-styles?

示例[简单]

<p class='txtBlack'>Hello World</p>

转换为

<p class='txtBlack' style='color:#000;'>Hello World</p>

希望这个清楚足够明白。

推荐答案

我将使用 element.currentStyle window.getComputedStyle )为每个元素,然后'手动'阅读我想要的,并覆盖我确信在邮件应用程序不起作用。

I'd use element.currentStyle and window.getComputedStyle() for each element, then 'manually' read what I want and overwrite what I'm sure that doesn't work in mail apps.

我在这里做了例子: http://jsfiddle.net/Vmc7L/

另一种方法是读取规则表单样式表,然后将其应用于内联样式。但是如果你有一个选择器,如 .myClass:firstChild> .anotherClass ? :D可能jquery可以帮助。

Another way, is to read rules form style sheets and then apply them to inline style. But what if u got selectors like .myClass:firstChild>.anotherClass? :D Maybe jquery can help.

有你需要的方法: http://www.quirksmode.org/dom/w3c_css.html

这篇关于将引用的样式表动态添加到内联样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆