DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> CSS入門知識 >> DIV十CSS布局 >> 布局實例
DIV 背景圖在 Firefox 消失?加上 overflow:auto 就好
編輯:布局實例     

用父容器背景圖做偽欄位對齊,是常見技巧。但當子元素設了 float 之後,父容器的背景圖在 Firefox 下卻可能整個消失。本文示範如何修正。

問題結構

<div id="footer">
  <div id="footer_left">Content1</div>
  <div id="footer_right">Content2</div>
</div>

#footer {
  width:730px;
  background-image: url(../images/bg.jpg);
  background-repeat: repeat-y;
}
#footer_left  { float:left; width:230px; }
#footer_right { float:left; width:500px; }

這是左右兩欄排版,利用父容器 footer 的背景圖,讓兩個子欄位看起來高度對齊。

原因與解法

問題出在 footer_left 與 footer_right 都設了 float:left。在 Firefox 裡,子元素一旦浮動,父容器就不會被撐開,高度變成 0,背景圖自然看不到。只要在 #footer 加上 overflow:auto 讓它被浮動內容撐開即可:

#footer {
  width:730px;
  background-image: url(../images/bg.jpg);
  background-repeat: repeat-y;
  overflow:auto;
}
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved