Bootstrap 按钮屏幕底部中心

时间:2021-03-20 12:09:31

标签: html css twitter-bootstrap bootstrap-4 twitter-bootstrap-3

我是引导程序和学习新事物的新手,我正在尝试将引导程序按钮带到底部位置的屏幕中心,到目前为止我的代码是

.bottom-center {
  position: absolute;
  bottom: 0;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<p>Just a test of placing the button in center of the screen at bottom position</p>
<div class='bottom-center'>
  <button type='button' class='btn btn-primary btn-large btn-start'>Center</button>
</div>

1 个答案:

答案 0 :(得分:1)

不需要任何额外的 CSS 来实现这一点。

  1. 第一件事:使用引导程序 4 而不是引导程序 3。(引导程序 3 太旧了)
  2. fixed-bottom 类添加到按钮容器以使其位于屏幕底部。
  3. d-flex justify-content-center 添加到按钮容器以使其居中

阅读有关 bootstrap 中的 flex 属性的更多信息 here

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<p>Just a test of placing the button in center of the screen at bottom position</p>
<div class="fixed-bottom d-flex justify-content-center">
  <button type='button' class='btn btn-primary btn-large btn-start'>Center</button>
</div>