2013-08-27 129 views

回答

2

嘗試添加一個空格與clear:both CSS屬性或設置一個高度,以您的主格。

<div id="content"> 
    <div id="float-left">Some Text floating left</div> 
    <div id="float-right">Some Text floating right</div> 
    <div id="clear"></div> 
</div> 

CSS代碼

#content { 
    background-color:red; /* The background you want */ 
    width:500px; /* Demo: not important */ 
} 

#float-right { 
    float:right; 
    width:300px; 
    padding-right:20px; 
    line-height:200%; 
    background-color:#f2f2f2 
} 

#float-left { 
    float:left; 
    width:50px; 
    background-color:#e1e1e1 
} 

#clear{ 
    clear:both 
} 

See Demo

+0

你在我的代碼中改變了什麼?我看不到任何東西 –

+0

我編輯了,我輸入了錯誤的鏈接 –

+0

謝謝Fabien Papet –

0

這是因爲你的父母DIV沒有高度。您將子DIV設置爲浮動,以免影響父DIV的大小。您需要手動爲父DIV設置高度或使用clear:both;屬性

+0

我該在哪裏必須使用'clear:both'? –

+2

你需要在父DIV中添加一個新的DIV(在2個子DIV之後)並且定義爲clear:both;在新的DIV的style屬性中 – KwanMan