2013-12-13 17 views

回答

2

您應該在div上使用overflow: auto,它會根據div的內容擴展div。

<div style="border: 1px solid black; overflow: auto"> 
    <button style="float: right; padding: 10px;">this is button</button> 
</div> 

http://jsfiddle.net/jMshh/

這裏是一個教程,詳細解釋了溢出是如何工作的: http://css-tricks.com/the-css-overflow-property/

+0

+1:謝謝!有效! –

+0

+1是因爲大多數人使用'auto'而不是'hidden'。 – LinkinTED

0

你需要清除浮動,否則容器會崩潰到零高度。有很多方法可以做到這一點。這裏有一個例子:

<div style="border: 1px solid black;"> 
    <button style="float: right; padding: 10px;">this is button</button> 

    <div class="clearfix"></div> 
</div> 

.clearfix { 
    clear: both; 
} 
0

用途: - <div style="clear: both;"></div>

<div style="border: 1px solid black;"> 
    <button style="float: right; padding: 10px;">this is button</button> 
    <div style="clear: both;"></div> 
</div> 
0

使用overflow: hidden父DIV。

0

使用明確的修復

.clear:after, .clear:before { 
    content: "\0020"; 
    display: block; 
    height: 0; 
    overflow: hidden; 
} 
.clear:after { 
    clear: both; 
} 

http://jsfiddle.net/jMshh/