让iframe调用页面的背景透明

需求:在一个div里面嵌套一个iframe(src="ui.html"),div有背景图片,要让iframe里的内容透明地显示在div层上。

      刚开始直接把iframe放在div中,结果iframe的背景(默认为白色)挡住了div层的背景,后来在ui.html的最外层div的style上加了background:transparent;属性,FF下显示透明,但在IE下iframe的背景为透明的(改变桌面的窗口颜色 ,效果会更清晰),依然挡住了div层的背景。后来又在iframe标签上加了一个 allowtransparency="true"属性,OK这下就满足需求啦。完整HTML如下:

div:

<div style="900px;height:30px;background:url("/img/l.gif") repeat-x;text-align:left">  
    <iframe width="300px" height="30px" style="float:left;" frameborder="0" scrolling="no" align="top" src="/ui.html"></iframe>  
</div>  

 ui.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html>  
  <head>  
  </head>  
  <body style="background:transparent;">  
    <div id="uui">  
        欢迎大家光临!!!  
    </div>  
  </body>  
</html>  
原文地址:https://www.cnblogs.com/shark1100913/p/5718206.html