iframe背景透明的设置方法

本文详细介绍了如何通过allowtransparency属性和背景颜色设置使iframe元素实现透明效果,包括使用`allowtransparency=true`和确保iframe内容源文档或body元素的背景色为transparent。

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

iframe背景透明的设置方法

1.与 iframe 元素一起使用的 allowtransparency 标签属性必须设置为 true。

2.在 iframe 内容源文档,background-color 或 body 元素的 bgcolor 标签属性必须设置为 transparent

<iframe src="./ads_top_tian.html"allowtransparency="true"style="background-color=transparent"title="test"frameborder="0"width="470"height="308"scrolling="no"></iframe>

当然前提是iframe页面中没有设置颜色.

在上面我们主要是看到了style中的一句代码style="background-color=transparent" 通过以下四种IFRAME的写法我想大概你对iframe背景透明效果的实现方法应该会有个清晰的了解:

<IFRAME ID="Frame1"SRC="transparentBody.htm"allowTransparency="true"></IFRAME>

<IFRAME ID="Frame2"SRC="transparentBody.htm"allowTransparency="true"STYLE="background-color: green"> </IFRAME>

<IFRAME ID="Frame3"SRC="transparentBody.htm"></IFRAME>

<IFRAME ID="Frame4"SRC="transparentBody.htm"STYLE="background-color: green"> </IFRAME>

现在我们来看一个实例

本例主要是iframe对象的allowTransparency属性应用,在该属性设置为true并且iframe所载加页的背景颜色设置为transparent(透明)时iframe将透明化。

allowTransparency设置或获取对象是否可为透明。

bgColor 设置或获取对象的背景颜色

父页面

<html>

<head>

<metahttp-equiv="Content-Type"content="text/html; charset=gb2312">

<title>父页面</title>

</head>

<bodybgcolor="#FF0000">

<iframesrc="index.htm"allowTransparency="true"></iframe>

</body>

</html>

子页面

<html>

<head>

<metahttp-equiv="Content-Type"content="text/html; charset=gb2312">

<title>子页面</title>

<styletype="text/css">

body

{

    background-color: transparent;

}

</style>

</head>

<body>

</body>

</html>

使用iframe在页面最上方

    <div style="width: 100%;height: 100%;" >

      <iframe src="http://xxxxxxxxxxx:8080" allowtransparency="true" style="position: fixed;left: 0;top: 0;z-index: 33;width: 100%;height: 100%;" frameborder="0" scrolling="no"><p>Your browser does not support iframes.</p>

</iframe>

    </div>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值