如何创建文本居中的引导圆形按钮

Lea*_*ner 6 css bootstrap-4

我正在尝试添加一个圆形按钮的数字按钮。我能够做到这一点,但文本(数字不居中)。理想情况下,如果我有 1 到 15 个圆形 15 个按钮,从 1 到 15

代码如下

body {
  padding: 1em;
}
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)

上面的代码是从这个链接使用的

小智 6

一个非常简单的课程将解决您的问题 -

<button type="button" class="btn btn-info p-5 rounded-circle btn-lg">100</button>
Run Code Online (Sandbox Code Playgroud)

<button type="button" class="btn btn-info p-5 rounded-circle btn-lg">100</button>
Run Code Online (Sandbox Code Playgroud)


Dir*_*ber 1

您必须包含 CSS 才能.btn-circle获得圆角。我从您提供的链接中复制了 CSS,并删除了所有填充,使文本居中。这将导致:

.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;
}
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)