Bootstrap 4垂直对齐2度之间-Flex

时间:2019-03-25 14:06:33

标签: html css css3 flexbox bootstrap-4

我正在尝试在一个具有相同高度的主div中连接2个div,第一个div具有slider(caroseul),第二个div具有一些img和文本。调整窗口大小时,我想使第二个divs图像与第一个divs高度(轮播图像高度)相同。

我的Codepen在这里: https://codepen.io/anon/pen/drrewJ#anon-login

这是我的代码;

<div class="row">

<div class="col-md-8 col-xl-8 b">
<!-- b is border radius for see effect -->
<div class="container">

<div class="bd-example">
  <div id="carouselExampleCaptions" class="carousel slide" data-ride="carousel" data-interval="3000">
    <ol class="carousel-indicators">
      <li data-target="#carouselExampleCaptions" data-slide-to="0" class="active"></li>
      <li data-target="#carouselExampleCaptions" data-slide-to="1"></li>
      <li data-target="#carouselExampleCaptions" data-slide-to="2"></li>
    </ol>
    <div class="carousel-inner">
      <div class="carousel-item active">
        <img src="https://via.placeholder.com/1250x650" class="d-block w-100" alt="...">
        <div class="carousel-caption d-none d-md-block">
          <h5>First slide label</h5>
          <p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
        </div>
      </div>
      <div class="carousel-item">
        <img src="https://via.placeholder.com/1250x650" class="d-block w-100" alt="...">
        <div class="carousel-caption d-none d-md-block">
          <h5>Second slide label</h5>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
        </div>
      </div>
      <div class="carousel-item">
        <img src="https://via.placeholder.com/1250x650" class="d-block w-100" alt="...">
        <div class="carousel-caption d-none d-md-block">
          <h5>Third slide label</h5>
          <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>
        </div>
      </div>
    </div>
    <a class="carousel-control-prev" href="#carouselExampleCaptions" role="button" data-slide="prev">
      <span class="carousel-control-prev-icon" aria-hidden="true"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="carousel-control-next" href="#carouselExampleCaptions" role="button" data-slide="next">
      <span class="carousel-control-next-icon" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
    </a>
  </div>
</div>  

</div> 

</div>

<div class="col-md-4 col-xl-4 b">
    <div class="container">
        <a href="#" >
            <div class="list-group">
               <li class="media">
                <img src="https://via.placeholder.com/100" class="img-fluid">
                <div class="media-body">List-based media object</div>
              </li>
            </div>
        </a>
        <a href="#" >
            <div class="list-group">
               <li class="media">
                <img src="https://via.placeholder.com/100" class="img-fluid">
                <div class="media-body">List-based media object</div>
              </li>
            </div>
        </a>
        <a href="#" >
            <div class="list-group">
               <li class="media">
                <img src="https://via.placeholder.com/100" class="img-fluid">
                <div class="media-body">List-based media object</div>
              </li>
            </div>
        </a>
    </div>
</div>
</div>

1 个答案:

答案 0 :(得分:0)

由于flexbox项的高度与最高高度相同,因此对flexbox行执行此操作的唯一方法是将内容绝对定位在“ taller” div中。

Flexbox最短列的高度

   <div class="col-md-4 col-xl-4 b overflow-auto">
            <div class="position-absolute">
                <a href="#">
                    <div class="list-group">
                        <li class="media">
                            <img src="https://via.placeholder.com/100" class="img-fluid">
                            <div class="media-body">List-based media object</div>
                        </li>
                    </div>
                </a>
                <a href="#">
                    <div class="list-group">
                        <li class="media">
                            <img src="https://via.placeholder.com/100" class="img-fluid">
                            <div class="media-body">List-based media object</div>
                        </li>
                    </div>
                </a>
                <a href="#">
                    <div class="list-group">
                        <li class="media">
                            <img src="https://via.placeholder.com/100" class="img-fluid">
                            <div class="media-body">List-based media object</div>
                        </li>
                    </div>
                </a>
                <a href="#">
                    <div class="list-group">
                        <li class="media">
                            <img src="https://via.placeholder.com/100" class="img-fluid">
                            <div class="media-body">List-based media object</div>
                        </li>
                    </div>
                </a>
                <a href="#">
                    <div class="list-group">
                        <li class="media">
                            <img src="https://via.placeholder.com/100" class="img-fluid">
                            <div class="media-body">List-based media object</div>
                        </li>
                    </div>
                </a>
            </div>
        </div>

https://www.codeply.com/go/gwrLQVU4VS