<div class="box">
<div class="a"></div>
<div class="b"></div>
</div>
box,a,b高度都根据内容增加,b的高度比a高,于是撑大box,这时a的高度怎么能和b或者box一样呢
我可以理解为css中的等高布局的话,有那么几种方法: http://www.w3cplus.com/css/creaet-equal-height-columns
html,body,box,a,b{
height:100%
}
父元素设置高度100%
http://jsbin.com/ruqebozetu/edit?html,css,output 你看看是否是你想要的效果.JQ做的.
<style type="text/css">
<!-- display: table-cell-->
.a,
.b {
width: 50%;
color: white;
}
.a {
background-color: olive;
}
.b {
background-color: blue;
}
.box {
border: 1px solid red;
display: table;
width: 100%
}
.a,
.b {
display: table-cell;
vertical-align: top;
color: white;
}
</style>
<div class="box">
<div class="a">css元素的高度怎么自动扩充到100%</div>
<div class="b">
<p>css元素的高度怎么自动扩充到100%</p>
<p>css元素的高度怎么自动扩充到100%</p>
</div>
</div>
<!-- flex -->
<style type="text/css">
.a,
.b {
width: 50%;
color: white;
}
.a {
background-color: olive;
}
.b {
background-color: blue;
}
.box {
border: 1px solid red;
display: -webkit-flex;
-webkit-flex-flow: row wrap;
display: -ms-flexbox;
-ms-flex-flow: row wrap;
}
</style>
<div class="box">
<div class="a">css元素的高度怎么自动扩充到100%</div>
<div class="b">
<p>css元素的高度怎么自动扩充到100%</p>
<p>css元素的高度怎么自动扩充到100%</p>
</div>
</div>
a,b是浮动的,要想让a,b平行 ,是这个意思吗
要是高度无法固定的话,可以用js动态设置a.style.height = b.style.height
100%是根据父级高度定的
.box{
width:500px;
border:1px solid #ccc;
position: relative;
}
.a{
width:40%;
height:100%;
border:1px solid #f8d5d8;
position: absolute;
top:0;
bottom:0;
}
.b{
width:40%;
min-height:300px;
margin-left:41%;
border: 1px solid #008080;
}
优点:满足你的题目要求
缺点:1.b的高度必须比a大,比较局限
如果对CSS3的新功能支持较好,建议用flex
http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html
flexbox