Bootstrap 4 - Vertical Center List Items

I have a webpage using the beta version of Bootstrap 4. This page has a built-in list. I want the contents of each list item to be vertically centered so that the items line up. As shown in this Bootply , they are currently out of center. I am using the following code:

<ul class="list-inline text-center align-items-center">
  <li class="list-inline-item"><h2>Hello</h2></li>
  <li class="list-inline-item"><button class="btn btn-info btn-sm">Help</button></li>
</ul>

My question is: how to get list items so that they are vertically centered?

+4
source share
3 answers

It looks like flexbox has not been applied

Try the following:

.align-items-center {
    -ms-flex-align: center!important;
    align-items: center!important;
    display: flex;
    justify-content: center;
}

Bootply Demo

: CSS , . li... ... , , , .

+2

flexbox utils ( CSS ).

<ul class="list-inline text-center d-flex justify-content-center align-items-center">
  <li class="list-inline-item"><h2>Hello</h2></li>
  <li class="list-inline-item"><button class="btn btn-info btn-sm">Help</button></li>
</ul>

https://www.bootply.com/NLcGDLFEjJ

+2

It is very simple. Just add the bootstrap class align-middleto the tags <li>.

<ul class="list-inline text-center align-items-center">
  <li class="list-inline-item align-middle"><h2>Hello</h2></li>
  <li class="list-inline-item align-middle"><button class="btn btn-info btn-sm">Help</button></li>
</ul>

Hope this helps. You can check the result here .

0
source

Source: https://habr.com/ru/post/1684461/


All Articles