IE浏览器中iframe背景BODY透明

本文介绍了解决IE浏览器中iframe出现默认白色背景及边框问题的方法,通过设置iframe的属性实现背景透明,并展示了具体的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

IE浏览器中iframe会出现默认的白色背景及边框,影响美观。有边框的正常,但IE默认的HTML背景色为白色,而FF默认背景色为透明色。
此外iframe在IE中长宽为300*150,其中边框为2px宽;FF 中为304*154,边框也同样为2px。(这里所说宽算边框的宽度)
现有两个文件:main.html 和t ransparentBody.html
其中transparentBody.htm是嵌套在main.htm之中,为了便于看效果在BODY中加入蓝色背景请看效果图:

main.html代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>main</title> </head> <body style="background-color:blue;"> <iframe name="main" src="transparentBody.htm"></iframe> </body> </html>
ransparentBody.html代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>transparentBody</title> </head> <body> ... </body> </html>
首先,在transparentBody.htm的<body>中设定style="background-color:transparent",即为透明样式
然后,在<iframe name="main" src="transparentBody.htm"></iframe>之中加入   frameborder="0"和allowTransparency="true"
<iframe name="main" src="transparentBody.htm" frameborder="0" allowTransparency="true"></iframe> 到此,iframe背景透明效果搞定。
代码中
allowTransparency指是否允许透明,
frameborder="0"是指边框为不可见。

转载于:https://www.cnblogs.com/ahjesus/archive/2010/07/31/1998653.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值