Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 4: Button align text with icon

So I'm making a button with an icon on the left. And the alignment is messed up. My text doesn't middle align with the icon and I have no idea how to fix this. Line-height doesn't seem to do anything. Or touching the padding/margins because I've added the padding to the icon area because I need it to be darker than the text background.

Here's the image preview:

enter image description here

Is there a way I can fix the alignment? Or is there a way to do this type of a button easier with Bootstrap 4?

Here's my code:

.btn-primary {
    background-color: #3382c7;
    font-size: 10px;
    font-weight: bold;
    text-transform: uppercase;
    span {
      padding-left: 25px;
      padding-right: 25px;
    }
    i {
      font-size: 20px;
      background-color: #306fa5;
      padding: 15px 20px;
    }
  }
<a href="#" class="btn btn-primary border-0 rounded-0 p-0">
  <i class="fa fa-play" aria-hidden="true"></i>
  <span>Click here to Play</span>
</a>
like image 883
Retros Avatar asked May 03 '17 11:05

Retros


2 Answers

Use align-middle class on the span and icon..

<div class="container">
    <a href="#" class="btn btn-primary border-0 rounded-0 p-0">
        <i class="fa fa-play align-middle" aria-hidden="true"></i>
        <span class="align-middle">Click here to Play</span>
    </a>
</div>

http://www.codeply.com/go/xuiy1703Dv

like image 113
Zim Avatar answered Sep 21 '22 16:09

Zim


If you make them display: inline-block and vertical-align: middle it should work for you

.btn-primary {
    background-color: #3382c7;
    display: inline-block;
    font-size: 10px;
    font-weight: bold;
    text-transform: uppercase;
}

.btn-primary span {
    display: inline-block;
    padding-left: 25px;
    padding-right: 25px;
    vertical-align: middle;
}

.btn-primary i {
    font-size: 20px;
    display: inline-block;
    background-color: #306fa5;
    padding: 15px 20px;
    vertical-align: middle;
}
<a href="#" class="btn btn-primary border-0 rounded-0 p-0">
  <i class="fa fa-play" aria-hidden="true"></i>
  <span>Click here to Play</span>
</a>
like image 44
Paul Avatar answered Sep 23 '22 16:09

Paul