Align contents in the middle of a div

I would like to align the contents of my second column in the middle of the div. I tried to try in different ways, but have not yet found how. I am using Bootstrap 4.

Could you tell me how to do this?

<div class="card">
   <div class="card-body">
      <div class="row">
         <div class="col-md-1">
            <img class="rounded-circle img-thumbnail d-inline"
                 src="..."
                 height="65px"
                 width="65px"
                 alt="User image">
         </div>
         <div class="col-md-11">
            <p class="d-inline">...</p>
            <button class="close" type="button"><span class="fa fa-times" aria-hidden="true"></span></button>
         </div>
      </div>
   </div>
</div>

I am sure that I will miss something very simple, but I do not know what.

JSFiddle example

Thank you for your help:)

+4
source share
3 answers

To get the vertical center

<div class="col-md-11 align-self-center">
    <p class="d-inline">Kitten</p>
    <button class="close" type="button"><span class="fa fa-times" aria-hidden="true"></span></button>
</div>
+1
source

Use a class text-center.

 <div class="card">
  <div class="card-body">
    <div class="row">
      <div class="col-md-1">
        <img class="rounded-circle img-thumbnail d-inline" src="https://4fi8v2446i0sw2rpq2a3fg51-wpengine.netdna-ssl.com/wp-content/uploads/2016/06/KittenProgression-Darling-week7.jpg" height="65px" width="65px" alt="User image">
      </div>
      <div class="col-md-11 text-center"><!--Modification here -->
        <p class="d-inline">Kitten</p>
        <button class="close" type="button"><span class="fa fa-times" aria-hidden="true"></span></button>
      </div>
    </div>
  </div>
</div>

Demo: https://jsfiddle.net/2hjxszck/1/

+3
source

Add this css to the vertical and horizontal center

button.close {
    padding: 0;
    background: 0 0;
    border: 0;
    -webkit-appearance: none;
    line-height: 65px;
    text-align: center;
}
.d-inline {
    display: inline!important;
    line-height: 65px;
    text-align: center;
}

and text center class for col-md-11 <div class="col-md-11 text-center">

0
source

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


All Articles