嵌套列中的引导行,响应高度

时间:2016-06-01 19:23:52

标签: css twitter-bootstrap grid flexbox

我正在尝试让灰色文本填充此列中的其余可用空间,同时使用窗口大小(剩余的100px左右)进行增长/缩小。灰色文本区域的底部应该与左侧的大图像均匀。

我在想有一个flexbox解决方案,但似乎没有任何效果。

也许解决方法是从整个右列中删除BS类?并用更多的CSS写这个部分?

Mockup for design

img {width:100%}
.content-text {background:gray; margin-top:15px;}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
   <div class="container-fluid">

    <div class="row">

        <div class="col-md-6">

            <div class="content-box">
                <div class="item">
                    <a href="#">
                        <img class="content-img" src="http://c7.staticflickr.com/9/8192/8086114606_c8b71f3277_b.jpg" alt="" />
                    </a>
                </div>
            </div>

        </div><!-- col -->

        <div class="col-md-6">

            <div class="row">

                <div class="col-sm-6">
                    <div class="content-box">
                        <div class="item">
                            <a href="#">
                                <img class="content-img" src="http://c5.staticflickr.com/8/7350/14012783868_630bff261c_b.jpg" alt="" />
                            </a>
                        </div>
                    </div>

                </div><!-- col -->

                <div class="col-sm-6">

                    <div class="content-box">
                        <div class="item">
                            <a href="#">
                                <img class="content-img" src="http://c5.staticflickr.com/8/7350/14012783868_630bff261c_b.jpg" alt="" />
                            </a>
                        </div>
                    </div>

                </div><!-- col -->

            </div>

            <div class="row">

                <div class="col-md-6">
                    <div class="content-box">
                        <div class="item">
                            <div class="content-text">
                                <p>hello world</p>
                            </div><!-- content-text -->
                        </div><!-- item -->
                    </div><!-- content-box -->
                </div><!-- col -->

                <div class="col-md-6">

                    <div class="content-box">
                        <div class="item">
                            <div class="content-text">
                                <p>hello world</p>
                            </div><!-- content-text -->
                        </div><!-- item -->
                    </div><!-- content-box -->

                </div><!-- col -->

            </div><!-- row -->

        </div><!-- col -->

    </div><!-- row -->

    <div class="row">

        <div class="col-md-6">

            <div class="placeholder-box"></div>

        </div><!-- col -->

        <div class="col-md-6">

            <div class="row">

                <div class="col-md-6">

                    <div class="placeholder-box"></div>

                </div><!-- col -->

                <div class="col-md-6">

                    <div class="placeholder-box"></div>

                </div><!-- col -->

            </div><!-- row -->

        </div><!-- col -->

    </div><!-- row -->

</div><!-- container -->

1 个答案:

答案 0 :(得分:1)

试试这个,不是我确定的最好的代码,而是我现在能想到的。

解决方案很简单:

  • 使用flexbox制作前两个col相等的高度
  • 然后将容器放在右侧col(包含2个小col - 我在这里修改你的html结构,希望你的意图不会出错)右侧col的全高度
  • 在其中一个容器中添加背景
  • 使 content-text 区域具有边框顶部,使其看起来与img分开。

这一切,您可以在下面的代码中更好地看到它。希望它有所帮助!

img {width:100%}
.content-box {background-color: gray}
.content-text {border-top:15px solid white;}
.row-eq-height {display: flex; flex-wrap: wrap}
.fullHeight {display: flex}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
   <div class="container-fluid">
    <div class="row row-eq-height">
        <div class="col-md-6">
            <div class="content-box">
                <div class="item">
                    <a href="#">
                        <img class="content-img" src="http://c7.staticflickr.com/9/8192/8086114606_c8b71f3277_b.jpg" alt="" />
                    </a>
                </div>
            </div>
        </div><!-- col -->

        <div class="col-md-6 fullHeight">
            <div class="row fullHeight">
                <div class="col-sm-6 fullHeight">
                    <div class="content-box fullHeight">
                        <div class="item">
                            <a href="#">
                                <img class="content-img" src="http://c5.staticflickr.com/8/7350/14012783868_630bff261c_b.jpg" alt="" />
                            </a>
                          	<div class="content-text">
                                <p>hello world</p>
                            </div><!-- content-text -->
                        </div>
                    </div>
                </div><!-- col -->

                <div class="col-sm-6 fullHeight">
                    <div class="content-box fullHeight">
                        <div class="item">
                            <a href="#">
                                <img class="content-img" src="http://c5.staticflickr.com/8/7350/14012783868_630bff261c_b.jpg" alt="" />
                            </a>
                          	<div class="content-text">
                                <p>hello world</p>
                            </div><!-- content-text -->
                        </div>
                    </div>
                </div><!-- col -->
            </div>
        </div><!-- col -->
    </div><!-- row -->
    <div class="row">
        <div class="col-md-6">
            <div class="placeholder-box"></div>
        </div><!-- col -->
        <div class="col-md-6">
            <div class="row">
                <div class="col-md-6">
                    <div class="placeholder-box"></div>
                </div><!-- col -->
                <div class="col-md-6">
                    <div class="placeholder-box"></div>
                </div><!-- col -->
            </div><!-- row -->
        </div><!-- col -->
    </div><!-- row -->
</div><!-- container -->