我正在寻找一些替代的方法来完成以下操作:
<iframe transparency=true ...
当我进行W3C验证时,我遇到了以下错误:
Column 31: there is no attribute "allowtransparency"
如果使用这个CSS:
.iframe-trans-fix{
opacity: 0;
filter:alpha(opacity=0);
}
对于上面的代码片段,我得到了一个空白的iframe。
我正在寻找一些替代的方法来完成以下操作:
<iframe transparency=true ...
当我进行W3C验证时,我遇到了以下错误:
Column 31: there is no attribute "allowtransparency"
如果使用这个CSS:
.iframe-trans-fix{
opacity: 0;
filter:alpha(opacity=0);
}
对于上面的代码片段,我得到了一个空白的iframe。
虽然W3C的HTML规范没有定义它,但确实存在一个allowTransparency属性,并且所有现代浏览器(包括Internet Explorer)都支持它。正如HTML5所教给我们的,应该先有车再有马。
假设您在主页index.html上有以下HTML代码:
<html>
<body>
<iframe src="source.html"
allowTransparency="true"
style="background-color:lightgreen;"
width="400" height="200">
</iframe>
</body>
</html>
你的 source.html 文件应该长这样:
<html>
<body>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin gravida, magna
id bibendum sollicitudin, tellus tortor consequat enim, et mollis mauris
augue et dui. </p>
</body>
</html>
我不确定你在这里想要做什么,但这应该是你正在寻找的:
iframe {
background-color: transparent;
}
当然,这是基于您希望 iframe
的背景透明的假设。
<!--[if lt IE 9]><script> $(".classname").attr("allowTransparency", "true"); </script><![endif]-->
iframe {background-color:transparent}
,但在旧版IE上无效)没有名为transparency
的HTML属性,因此您将始终在iframe transparency=true
中收到错误。
如果将不透明度设置为零,则根本看不到该元素-您需要定义不透明度的程度:
opacity: 0.25; /* 所有现代浏览器 */
filter: alpha(opacity=25) /* IE */
首先,不存在“transparency =“true””这样的东西,所以那样行不通。
其次,您是想使背景透明还是整个iframe透明?
CSS Opacity属性使您在其上使用它的任何元素内部的所有内容都变为透明。不透明度从0到1缩放,其中0完全透明,0.5半透明,1完全可见。
如果您将其用于div或iframe(或任何内容),则背景和文本将全部同等淡化。
另一方面,在现代浏览器中,您可以使用RGBA颜色将背景设置为部分透明。您应该这样做:
iframe.transparent {
background-color: #FFF; /*this gives a background color for browsers that can't do RGBA color, like internet explorer*/
background-color: rgba(255,255,255,0.5);
}
RGBA颜色定义与不透明度属性(0 = 透明,1 = 不透明)的工作方式相同,只是它仅使您设置的特定项目透明,并且不影响该项目内部的项目(即它不会影响iframe中的文本)。前三个数字是从0到255的比例尺上您的颜色的红色,绿色和蓝色值。
如果您想要更好的跨浏览器解决方案,我建议您只使用透明的.png文件作为背景图像。您将不得不在IE上进行测试,不确定它是否适用于特定的iframe,但您可以在iframe上设置无背景,然后将透明图像设置为加载在iframe内的页面的背景(将其应用于该页面的body元素)。
希望这有所帮助!