Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertical alignment within Bootstrap grid

It seems like a simple question, but I simply can't find an answer.

This fiddle should be fairly straightforward: http://fiddle.jshell.net/52VtD/4040/

enter image description here

<div class="panel panel-default entete" >
    <div class="row">
        <div class="col-md-6">
            <div class="title">
               to be centered vertically
            </div>
        </div>
        <div class="col-md-2">
            <p>Text</p>
            <p>Text</p>
            <p>Text</p>
        </div>
        <div class="col-md-2">
            Text
        </div>
        <div class="col-md-2">
            Text
        </div>
    </div>
</div>

I'm trying to align vertically the contents of the first column relatively to the others.

If the window is resized (and there is no column to its right), the first column should be as high as its content (cannot use a fixed height).

like image 395
DavidZ Avatar asked Oct 28 '25 09:10

DavidZ


1 Answers

The correct way to do this using Bootstrap 4 Grid is by using one of then align-items-... classes on the .row element, or align-self-... on the .col elements.

In the case of the OP's original request, the best implementation would be

<div class="col-md-6 align-self-center">
    <div class="title">
       to be centered vertically
    </div>
</div>

If you wanted to, for example, set all of the .col elements to be aligned to the bottom vertically, you would set align-items-end on the .row element like so:

<div class="row align-items-end">

Source: https://getbootstrap.com/docs/4.0/layout/grid/#vertical-alignment

like image 83
Matt Rabe Avatar answered Oct 31 '25 00:10

Matt Rabe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!