Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Badge - Text Not Centered in Badge

I can't figure out how to get my text to align with the middle of my icon. This is using Chrome. See this fiddle.

@import url('https://fonts.googleapis.com/icon?family=Material+Icons');

.row {
  background: #f8f9fa;
  margin-top: 20px;
}

.col {
  border: solid 1px #6c757d;
  padding: 10px;
}
<link href="//stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />

<label class="badge badge-secondary align-middle">
  <span class="pb-2">Should Be Centered</span>
  <i class="material-icons md-18">cancel</i>
</label>

Any suggestion is welcome!

Example image:

enter image description here

like image 800
theMayer Avatar asked Jun 07 '18 16:06

theMayer


Video Answer


2 Answers

You'd want to put align-middle on the badge contents, instead of the badge...

  <label class="badge badge-secondary">
    <span class="pb-2 align-middle">Should Be Centered</span>
    <i class="material-icons md-18 align-middle">cancel</i>
  </label>

Demo with MD icon: https://www.codeply.com/go/TkAEvkUcXB

like image 81
Zim Avatar answered Oct 07 '22 19:10

Zim


You can Bootstrap Flex utilities to happen this.

<label class="badge badge-secondary d-inline-flex align-items-center justify-content-start">
    <span>Should Be Centered</span>
    <i class="material-icons md-18">cancel</i>
</label>

Codepen example.

like image 22
Arup Rakshit Avatar answered Oct 07 '22 19:10

Arup Rakshit