我想創建一個簡單的標題+內容+頁腳+側欄。側邊欄必須懸浮在頁眉和內容元素上方,並且如果內容比內容高,則必須將頁腳向下推(如下所示:http://jsfiddle.net/gWLFN/7/)。浮動右元素推下IE7中的下一個元素
的HTML:
<div id="wrapper">
<div id="sidebar">sidebar</div>
<div id="header">header</div>
<div id="content">content</div>
<div style="clear:both"></div>
<div id="footer">footer</div>
</div>
的CSS:
#wrapper { width:500px }
#header { width:500px; height:100px; background-color:red }
#content { width:500px; height:300px; background-color:green }
#footer { width:500px; height:100px; background-color:blue }
#sidebar {
float:right;
margin-top:50px;
width:100px;
height:500px;
background-color: yellow;
border:1px solid white;
}
的問題是,在IE7中,邊欄下推其他元素。我認爲這是因爲標題+側欄的總寬度大於包裝寬度。我在IE7中發現了很多關於float:right的問題,但是它們都是寬度不超過wrapper的。
我選擇了float:right而不是絕對定位,因爲footer的位置必須依賴側邊欄高度(如果有人知道如何用絕對定位完成這個操作,那麼完美!)。
我希望有任何想法來解決這個問題。
完美!我曾試過沒有寬度,但與該元素命令它沒有工作。隨着你的改變,一切都在原地。 – mariogl 2012-02-23 11:24:31