iframe的背景顏色在IE下為window的當前窗口顏色(默認白色,可以在顯示外觀處對其進行設置),這導致在大幅背景上插入iframe時,需要給它“透底”,可是IE不支持對iframe設置背景色,那怎么辦呢?
IE5.5開始支持浮動框架的內容透明。如果想要為浮動框架定義透明內容,則必須滿足下列條件。
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 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> 現(xiàn)在我們來看一個實例 本例主要是iframe對象的allowTransparency屬性應用,在該屬性設置為true并且iframe所載加頁的背景顏色設置為transparent(透明)時iframe將透明化。 allowTransparency設置或獲取對象是否可為透明。 bgColor 設置或獲取對象的背景顏色
父頁面
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>父頁面</title> </head> <body bgcolor="#FF0000"> <iframe src="index.htm" allowTransparency="true"></iframe> </body> </html>
子頁面
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>子頁面</title> <style type="text/css"> body { background-color: transparent; } </style> </head> <body> </body> </html>
<body style="background-color:transparent" > 或 <body bgColor="transparent">
<iframe src="about.htm" width="100%" height="100%" align="center" scrolling="auto" frameborder="0" style="filter:chroma(color=#ffffff)" >
</iframe>
<iframe src="about.htm" width="100%" height="100%" align="center" scrolling="auto" frameborder="0" allowTransparency="true" >
</iframe>
<iframe src="about.htm" allowTransparency="true" style="background-color: green"> </iframe >
<iframe src="about.htm"> </iframe >
<iframe src="about.htm" style="background-color: green"> </iframe >
<iframe id="iframeRight" src="/111.html" scrolling="no" width="100%" height="100%" frameborder="0" allowTransparency="true"></iframe>
<style>
body{
background-color:Transparent;
}
</style>
<div style="width:144px;height:557px;" id="divFloat1">
<img src="/image/fd_4.png" usemap="#Map20" border="0" />
</div>
如對本文有疑問,請?zhí)峤坏浇涣髡搲?,廣大熱心網友會為你解答!! 點擊進入論壇