Srl*_*rle 0 css twitter-bootstrap-3
为什么嵌套.row占用父.row的高度?
例:
<div class="container">
<div class="row"> <!-- Parent .row -->
<div class="col-md-8">
<div class="col-md-6"></div>
<div class="col-md-3"></div>
<div class="col-md-3"></div>
<div class="row"> <!-- nested PROBLEMATIC ROW -->
<div class="col-md-12">
Why this row has height of 300px instead of 150px?
I can solve problem by setting 'clear: both' on that
row, but class .row should do it by itself.
</div>
</div>
</div>
<div class="col-md-4">
<div></div>
<div></div>
<div></div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
使用一些虚拟css:
.col-md-8 {
height: 500px;
background: #f0f0f0;
}
.col-md-6 {
height: 150px;
background: red;
}
.col-md-3 {
height: 150px;
background: blue;
}
.col-md-12 {
height: 150px;
background: yellow;
}
.col-md-4 {
height: 500px;
background #f0f0f0;
}
.col-md-4 > div {
margin-bottom: 10px;
height: 150px;
background: green;
}
Run Code Online (Sandbox Code Playgroud)
最终输出:
JS Bin:http://jsbin.com/nugoziju/1/edit
首先,你不应该在没有相应行的情况下将'col'放在bootstrap中.所以你的标记看起来像这样:
<div class="container">
<div class="row"> <!-- Parent .row -->
<div class="col-md-8">
<div class="row">
<div class="col-md-6"></div>
<div class="col-md-3"></div>
<div class="col-md-3"></div>
</div>
<div class="row"> <!-- nested PROBLEMATIC ROW -->
<div class="col-md-12">
Why this row has height of 300px instead of 150px?
I can solve problem by setting 'clear: both' on that
row, but class .row should do it by itself.
</div>
</div>
</div>
<div class="col-md-4">
<div></div>
<div></div>
<div></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
然后那是固定的.那排是150px高.
更新了jsbin:http://jsbin.com/nugoziju/7