【发布时间】:2012-08-28 20:11:23
【问题描述】:
我正在做一份报告,在报告中我必须呈现来自不同提供商的电子邮件,这些电子邮件带有自己的 css(通常是内联 css,但有时它们应用一般样式)。我通常使用 iframe 来封装 css,所以它不会破坏我的,但我现在不能使用它。
有没有不使用 iframe 封装 css 的方法?
这是我遇到的问题的一个示例:
<html>
<head>
<style>
// I enclose it to content so it doesn't override the email css
#my_content table, #my_content p {
color: black;
}
</style>
</head>
<body>
<div id='my_content'>
... some stuff ...
<div id='email'>
<html>
<head>
<style>
table {
margin-left: 100cm; // screws up all my tables
}
.... some styles that should only apply inside the email div ...
</style>
</head>
<body>
.... email content ...
</body>
</html>
</div>
</div>
</body>
</html>
我可以提取 html 结构并获取正文中的内容,但并不是我所有的电子邮件都会看起来像它应该的那样。此外,html 必须是有效的,所以任何建议都会很棒!
【问题讨论】:
-
是的!使用
scoped属性。但是,我不相信它在任何地方都得到支持。 (嗯,你可以在谷歌浏览器中打开它chrome://flags。) -
我确实使用类,让我在问题中更好地解释电子邮件如何破坏我的 css
-
哦,它可能是我正在寻找的范围属性,但它还不适用于任何主流浏览器:'( w3schools.com/html5/att_style_scoped.asp
-
我希望我可以同时输入每一个人的计算机,并从他们的搜索结果中屏蔽 w3schools。 只是说