浮动不动态扩展

时间:2013-09-23 21:56:19

标签: html css

我有css代码列a和列b我在我的代码中使用float来动态扩展列a但这不会发生,我想尽可能多地添加b列中的内容,a列展开请参阅我的代码在http://jsfiddle.net/hadinetcat/E8jd3/

我的代码:

CSS

.container {
  border: 1px solid #000000;
  overflow: hidden;
  width: 100%;
}

.left {
  width: 45%;
  float: left;
  background:none repeat scroll 0 0 lightblue;  
}

.right {
  width: 45%;
  float: right;
}

HTML

<div class = "container">
<div class="left">
column a
column a<br />
column a<br />
column a<br />
column a<br />
column a<br />
column a<br />
</div>


<div class="right">
column b<br />
dynamic row<br />
dynamic row<br />
dynamic row<br />
dynamic row<br />
dynamic row<br />
dynamic row<br />
dynamic row<br />
dynamic row<br />
dynamic row<br />
dynamic row<br />
dynamic row<br />
dynamic row<br />
dynamic row<br />
dynamic row<br />

</div>
</div>

<div style="clear: both;"></div>

3 个答案:

答案 0 :(得分:1)

您可以尝试使用display:table作为父级,然后使用display:table-cell作为列

CSS

<style>
.parent {
    display: table;  
    width:100%;
}

.left {
    display: table-cell; 
    width:200px;
    background-color:#0c0;
}

.right {
    width:auto;
    display: table-cell;
    background-color:#f00;
}

.footer {
    background-color:#eee;
}
</style>

HTML

<body>

    <div class="parent">
         <div class="left">aaaa</div>
         <div class="right">bb<br />bbb<br />bbb</div>
    </div>

    <div class="footer">Footer</div>

</body>

查看实际操作:http://jsfiddle.net/2JmBL/

答案 1 :(得分:1)

您好我已经更新了JSFiddle中的代码,

check it here : http://jsfiddle.net/btCQn/1/

<style>
.container {
  border: 1px solid #000000;
  overflow: hidden;
  width: 100%;
    position:relative;

}

.left {
  width: 45%;
  float: left;
  background:none repeat scroll 0 0 lightblue;
  position:absolute;
}

.right {
  width: 45%;
  float: right;

}
</style>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<script>
$(document).ready(function(){
$(".left").css("height",$(".right").height());
});
</script>

它的工作

答案 2 :(得分:1)

这是一个简单的解决方案(JSFiddle http://jsfiddle.net/Yjeq2/1/

(对您的HTML没有任何更改)

CSS

<style type="text/css"> html, body {
    font-family:verdana;
    font-size:12px;
}
.parent {
    border:1px solid red;
    width:100%;
    padding:5px;
    overflow:hidden;
}
.left {
    border:1px solid blue;
    width:200px;
    float:left;
    position:relative;
    padding:3px 0;
}
.right {
    border:1px solid green;
    width: calc(100% - 200px);
    padding:3px 0;
    margin-left: 200px;
}

 .left, .right {
    padding-bottom:8000px;
    margin-bottom:-8000px;
    background:none repeat scroll 0 0 lightblue;
}
.clr {
    clear:both;
}
.footer {
    border:1px solid orange;
    position: relative;
    padding:3px;
    margin-top:5px;
}
</style>