CSS溢出字符没有按下<div> </div>

时间:2013-06-30 10:17:31

标签: css

我有一个名为bigbox的<div>,其中包含一个名为包装的<div>。包装器包含2个<div>,称为文本框和复选框。如果文本框中的字符溢出,则不会推送下面的其他包装器。如何让下面的包装器停下来?

这里是jsfiddle:http://jsfiddle.net/WA63P/

enter image description here

 <html>
 <head>
<title>Page</title>
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>

<style type="text/css">


.bigbox  {
    background-color: #F5E49C;
    color: #000;
    padding: 0 5px;
    width:280px;
    height:500px;
    position: absolute;
    text-align: center;content: "";display: block;clear: both;
}



.box   {

    background-color: #272822;
    color: #9C5A3C;
    height:100px;
    width:260px;
    margin-bottom: 10px;
    position: relative; top:10px;
}   
.textbox
{
    background-color: #FFFFFF;
    color: #272822;
    height:100px;
    width:160px;float:left;text-align: left

}   
.checkbox
{
background-color: #FFFFFF;
height:50px;
width:50px;
float:right;
d
}   

</style>



 <div class="bigbox">

 <div class="box"> 
  <div class="textbox">background background background background background background background background background background background background background background background background background background background background background background </div>
  <div class="checkbox"> </div>
  </div>


 <div class="box"> 
  <div class="textbox"> </div>
  <div class="checkbox"> </div>
  </div>

 </body>
 </html>

1 个答案:

答案 0 :(得分:1)

.bigbox  {
    background-color: #F5E49C;
    color: #000;
    padding: 0 5px;
    width:280px;
    height:500px;
    position: absolute;
    text-align: center;content: "";display: block;
}

.box   {
    background-color: #272822;
    color: #9C5A3C;
    width:260px;
    margin-bottom: 10px;
    position: relative; top:10px;
}   
.textbox
{
    background-color: #FFFFFF;
    color: #272822;
    min-height:100px;
    width:160px;
    text-align: left;
}   
.checkbox
{
background-color: #FFFFFF;
width:50px;
position:absolute;
top:0px;
right:0px;
height:50px;
}   

删除float:left中的.textbox以使其成为静态,因为静态块会自动将其他静态块向下推。同时删除height以避免设置固定高度并允许其高度自动收缩/包裹。

要将复选框定位在图片中,您可以使用position:absolute; top:0px; right:0px;

检查demo