有没有办法“沙箱”?没有使用iframe的情况下,HTML页面的页面的CSS离开了吗? [英] Is there a way to "sandbox" an HTML block away from its page's CSS without using iframes?
问题描述
例如,是否有可能完全忽略CSS规则的 div
,无论 id
s它包含?
不幸的是)如果没有 iframe
,不可能。
您必须重置每个现有的CSS规则<$ c
$ $ $ $ $ $ $ $ b $ $ $ $ font-size:....
font-family:..........
margin:.........
padding:... ......
line-height:.........
}
虽然困难且从未100%可靠,但可能以这种方式获得可用的结果。您可以查看其中一个重置样式表,例如 Eric Meyer's < a>获取要重置的重要属性列表; 此处是声明为CSS 2.1属性的完整列表 - 不包括CSS 3和供应商特定的属性,您必须考虑这一点。
第三方小工具的提供者通常将其重置CSS作为HTML元素内部的内联CSS进行硬编码以覆盖任何!important
威胁覆盖sandbox类规则的规则。
Is it possible, for example, to have a div
that completely ignores CSS rules, no matter what class
es and id
s it contains?
Nope, this is (sadly) not possible without an iframe
.
You would have to reset every existing CSS rule for that div
like so:
div.sandbox
{
font-size: ....
font-family: ..........
margin: .........
padding: .........
line-height: .........
}
while difficult and never 100% reliable, it might be possible to achieve a usable result this way. You could look at one of the "reset stylesheets" like Eric Meyer's to get a list of important properties to reset; here is what claims to be a complete list of CSS 2.1 properties - excluding CSS 3 and vendor specific ones, which you would have to take into consideration as well.
Providers of 3rd party widgets often hard-code their "reset CSS" as inline CSS inside the HTML element to override any !important
rules that threaten to override the sandbox class's rules.
这篇关于有没有办法“沙箱”?没有使用iframe的情况下,HTML页面的页面的CSS离开了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!