0
我为不属于我的网站创建小部件。如何在嵌入小部件中应用css样式
HTML注入后,我做以下方式进行样式设置:
var style = document.createElement('style'),
stylesString = 'minified css with a prefix for each selector eg. .my-prefix p {... }',
rules = document.createTextNode(stylesString);
style.type = 'text/css';
if(style.styleSheet) {
style.styleSheet.cssText = rules.nodeValue;
} else {
style.appendChild(rules);
}
document.getElementsByTagName('head')[0].appendChild(style);
但一些网站上我的风格被覆盖。
有没有更精确地应用样式的方法?
我不希望(不能)使用:
- 的iFrame
- 重要的每个属性
我想省略id的使用,因为widget被放置在外部网站上。我正在考虑更多解析CSS的方向,并通过javascript将样式应用于特定元素... – czerasz 2012-04-10 09:00:38