2013-08-27 53 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