DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> HTML基礎知識 >> HTML和Xhtml
iframe 參數完整對照:從基本設定到邊框與留白控制
編輯:HTML和Xhtml     

iframe 可以嵌在網頁的任意位置,載入一個獨立的文件,常被拿來放廣告、第三方服務或舊系統頁面。要把它的外觀調到看不出接縫,得熟悉幾個關鍵屬性。

常用組合

<iframe src="test.jsp" width="100%" height="50"
        frameborder="no" border="0"
        marginwidth="0" marginheight="0"
        scrolling="no" allowtransparency="yes"></iframe>

ASP.NET 環境若需要在伺服器端控制 iframe 的跳轉,加上 runat="server":

<iframe runat="server" src="your-page-url" width="750" height="30"
        frameborder="no" border="0" marginwidth="0" marginheight="0"
        scrolling="no" allowtransparency="yes"></iframe>

核心屬性說明

  • src:要載入的網址(URl)。
  • frameborder:是否顯示邊框,0 無邊框、1 有邊框。
  • scrolling:yes 有捲軸、no 無捲軸、auto 自動。
  • allowtransparency:背景是否透明,yes 透明、no 不透明。

基本使用格式

<iframe src="URL" width="x" height="x" scrolling="[OPTION]"
        frameborder="x" name="main"></iframe>
  • src:檔案路徑,可以是 HTML,也可以是文字檔、ASP 等。
  • width / height:「內部框架」區域的寬與高。
  • scrolling:當 src 指定的內容超出可視區域時的處理方式。設 no 不出捲軸;auto 需要時才出現;yes 永遠顯示。
  • frameborder:區域邊框寬度。為了讓內框與鄰近內容融合,通常設為 0。
  • name:框架名稱,供辨識與 target 對應使用。

屬性總表

  • SRC=URI:嵌入式框架的頁面檔路徑。
  • NAME=CDATA:嵌入式框架的名稱。
  • LONGDESC=URI:描述。
  • WIDTH=Length:寬度。
  • HEIGHT=Length:高度。
  • ALIGN=[top|middle|bottom|left|right]:對齊方式。
  • FRAMEBORDER=[1|0]:框架邊框。
  • MARGINWIDTH=Pixels:左右留白。
  • MARGINHEIGHT=Pixels:上下留白。
  • SCROLLING=[yes|no|auto]:捲軸行為。

其他常用寫法

<iframe border="3"></iframe>              <!-- 邊緣寬度 -->
<iframe frameborder="0"></iframe>           <!-- 是否為立體邊框 -->
<iframe height="31" width="88"></iframe>    <!-- 寬高 -->
<iframe scrolling="no"></iframe>            <!-- 無捲軸 -->
<iframe src="girl.gif"></iframe>            <!-- 可載入圖片 -->

注意事項

一個浮動框架不需要透過 <frameset> 宣告就能存在,這也是它與傳統 <frame> 最大的不同。但要留意:WebTV 與 Netscape 4.x 不支援浮動框架;在 HTML 4.01 Strict 中 <iframe> 並未被定義(HTML5 才正式納入)。若需支援極舊環境,可用 <div> 搭配 CSS 定位模擬。

瀏覽器相容寫法建議

上述屬性多屬 HTML4 時代的呈現型寫法。現代專案建議改用 CSS 達到同樣效果:

iframe{
  border:0;              /* 取代 frameborder="0" */
  padding:0;             /* 取代 marginwidth/marginheight */
  background:transparent;/* 取代 allowtransparency */
  overflow:hidden;       /* 取代 scrolling="no" */
}

屬性寫法之所以仍值得知道,是因為維護舊系統時你一定會遇到;但新專案用 CSS 表達,語意更清楚、也更容易統一調整。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved