1

I have a small rounded circle with a number inside inside a button. How can i center the span vertical inside the button?

<button class="btn btn-primary w-50 my-4">
    Comments Moderation <span class="approve-counter rounded-circle bg-danger text-white text-center float-right">5</span>
</button>

CSS:

.approve-counter {
    width: 20px;
    height: 20px;
    line-height: 20px;
}

As you can see, the red circle is not exactly vertical in the middle of the blue button

Fiddle: https://jsfiddle.net/vour83s9/

Jack Maessen
  • 1,780
  • 4
  • 19
  • 51

1 Answers1

2

You can use flex and align-items: center to vertically center all items in the button. Apply the following styles to your button element:

.btn {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
}

Or even better, you could simply use Bootstrap 4 classes in your button tag to achieve the same result:

<button class="d-flex align-items-center justify-content-between btn btn-primary w-50 my-4">
    Comments Moderation <span class="approve-counter rounded-circle bg-danger text-white text-center float-right">5</span>
</button>
Alexander Belokon
  • 1,452
  • 2
  • 17
  • 37