0

I have two columns inside a row in Bootstrap 4. If I try to align vertically the content using align-items-center on the row, or align-self-center on the col, the h4 is centered but the background is not full height. Here is a pen https://codepen.io/geo555/pen/PyaLbE

<div class="container">
  <div class="row no-gutters justify-content-center">
    <div class="col-sm-4">
       <img src="https://via.placeholder.com/400X400" class="img-fluid">
    </div>
    <div class="col-sm-4 text-center bg-dark text-white align-self-center">
       <h4>Awesome desk</h4>
    </div>
   </div>
</div>
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
george
  • 81
  • 10

1 Answers1

2

Make the col d-flex flex-column and use vertical auto margin (my-auto) on the heading...

<div class="container">
    <div class="row no-gutters justify-content-center">
        <div class="col-sm-4">
            <img src="https://via.placeholder.com/400X400" class="img-fluid">
        </div>
        <div class="col-sm-4 border text-center bg-dark text-white d-flex flex-column">
            <h4 class="my-auto">Awesome desk</h4>
        </div>
    </div>
</div>

https://www.codeply.com/go/7nPpNbXHF4

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624