Bootstrap 3嵌套列,嵌套行高

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

bea*_*ane 5

首先,你不应该在没有相应行的情况下将'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

  • 从我所看到的,他们使用了另外一行:http://getbootstrap.com/css/#grid-nesting要避免的一件事是添加额外的'.container',这会破坏事物. (2认同)