【问题标题】:Is there a bootstrap 4 class to center a button horizontal?是否有引导程序 4 类将按钮水平居中?
【发布时间】:2019-03-04 21:04:22
【问题描述】:

我想将按钮水平居中。我可以用 CSS 做到这一点:

margin: 0 auto;
但是 Bootstrap4 中没有类可以做到这一点吗?

感谢您的帮助!

<!doctype html>
<html lang="en">
  <head>
    <title>Hello, world!</title>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
  </head>

  <body>
  <div class="container">
      <div class="row">
            <button type="button" class="btn btn-primary">Primary</button>
      </div>
 </div>

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
  </body>
</html>

【问题讨论】:

    标签: bootstrap-4


    【解决方案1】:

    这门课会让你

    <div class="container">
      <div class="row justify-content-center">
            <button type="button" class="btn btn-primary">Primary</button>
      </div>
    </div>
    

    其中使用flex

    这里是选项的完整列表Doc

    【讨论】:

      猜你喜欢
      • 2018-09-18
      • 2015-04-27
      • 2019-05-24
      • 1970-01-01
      • 2016-11-02
      • 2016-04-23
      • 2014-09-10
      • 2019-09-19
      • 2018-08-09
      相关资源
      最近更新 更多