Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertical align within a bootstrap card header

I am trying to use boostrap4 in order to create a card header where the title is text-align center of the card-header, an icone that is right align and both vertically center middle

I tried some things but nothing seems to get to what I want;

++++++++++++++++++++++++++++++++++++++++++++++++++++++
+                                                    +
+                        title                  icone+
+                                                    +
++++++++++++++++++++++++++++++++++++++++++++++++++++++

code:

<div class="card-header text-center bg-dark text-white">
            <div class="row h-100">
              <div class="col-md-11">
                <h5>Complete models list</h5>
              </div>
              <div class=col-md-1>
                <i class="far fa-question-circle float-right align-self-center"></i>
              </div>
            </div>

          </div>

any idea how to make it work ?

like image 394
Rafi Ki Avatar asked Mar 21 '18 16:03

Rafi Ki


1 Answers

Use align-items-center on the row...

 <div class="card-header text-center bg-dark text-white">
      <div class="row align-items-center">
             <div class="col-md-11">
                    <h5>Complete models list</h5>
             </div>
             <div class="col-md-1">
                   <i class="fa fa-question-circle float-right"></i>
             </div>
      </div>
 </div>

Or, to dead center the <h5> while keeping the icon right aligned, use a d-flex align-items-center div with auto-margins (ml-auto) to push the icon to the right...

<div class="card">
       <div class="card-header text-center bg-dark text-white">
             <div class="d-flex align-items-center">
                  <h5 class="mx-auto w-100">Complete models list</h5>
                  <i class="fa fa-question-circle ml-auto"></i>
             </div>
       </div>
       <div class="card-body">
             <p class="text-center">center</p>
       </div>
 </div>

Demo of both options

like image 155
Zim Avatar answered Nov 10 '22 21:11

Zim