Bootstrap 4 Vertical Align Between 2 Divs - Flex

2020-05-09 14:50发布

I'm trying connect 2 divs in one main div with same height, first div has slider(caroseul), second div has some img and text. I want to keep second divs images same with first divs height(carousel images height) when i resize the window.

My Codepen Here: https://codepen.io/anon/pen/drrewJ#anon-login

Here is my code;

<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条回答
乱世女痞
2楼-- · 2020-05-09 15:24

Since flexbox items will be the same as the height of the tallest, the only way to do this with a flexbox row is to absolute position the content in the "taller" div...

Flexbox height of shortest column

   <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://codeply.com/go/gwrLQVU4VS

查看更多
登录 后发表回答