Search code examples
cssbootstrap-4

How to create a bootstrap circled button with the text centered


I am trying to add a button for numbers a round button. I am able to do it but the text(number is not centered). Ideally if i have 1 to 15 circular 15 buttons from 1 to 15

Code below

body {
  padding: 1em;
}
<link
  href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"
  rel="stylesheet"
  id="bootstrap-css"
>


<button type="button" class="btn btn-info btn-circle btn-lg">100</button>

The above code is used from this link


Solution

  • You have to include the CSS for .btn-circle to have the rounded corners. I copied the CSS from the link you provided and removed all padding so the text is centered. This will result in:

    .btn-circle {
      width: 30px;
      height: 30px;
      text-align: center;
      padding: 0; // changed
      font-size: 12px;
      line-height: 1.428571429;
      border-radius: 15px;
    }
    .btn-circle.btn-lg {
      width: 50px;
      height: 50px;
      padding: 0; // changed
      font-size: 18px;
      line-height: 1.33;
      border-radius: 25px;
    }
    .btn-circle.btn-xl {
      width: 70px;
      height: 70px;
      padding: 0; // changed
      font-size: 24px;
      line-height: 1.33;
      border-radius: 35px;
    }
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
    <button type="button" class="btn btn-info btn-circle btn-lg">100</button>