html - bootstrap 4 在特定视口(viewport)禁用 mx-auto

标签 html css twitter-bootstrap bootstrap-4 viewport

我有两个按钮,当在响应式屏幕中时,它们需要水平居中,一个在彼此下方,而在较大的屏幕中,它们需要一个并排居中。

              <!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="css/bootstrap.min.css">


               <style>

                 section.masthead2{
                    background-color:orange;
                    background-repeat: no-repeat;
                    background-attachment: scroll;
                    background-position: center center;
                    -webkit-background-size: cover;
                    -moz-background-size: cover;
                    -o-background-size: cover;
                    background-size: cover;
                    height:80vh;
                    position:relative;
                  }
                  .gear {
                    height: 50px;

                  }
                  .botonhome{
                    background-color:#eb6626;
                    color: #ffffff;
                    padding-left:2em;
                    padding-right:2em;
                    font-family:'Josefin Sans', sans-serif;
                    font-weight:500;
                    border-radius:0.5em;
                    font-size:1.2em;
                    width:200px;
                  }
                  /*.contain{
                    position:absolute;
                    left:50%;
                    right:0;
                    transform:translateX(-50%);
                    bottom:0;
                  }*/
               </style>

            </head>
            <body>
            <section class="container-fluid masthead2 d-flex  align-items-center justify-content-center">

              <div class="container">
                <div class="row">
                    <div class="col-12 d-flex justify-content-center">
                        <h1 class="textoprincipal text-center">Lorem Ipsum is simply dummy text of the printing</h1>
                    </div>
                    <div class="col d-sm-flex  justify-content-center ">
                      <a class="btn botonhome   mr-sm-3 mb-3 " routerLink="/backoffice/job" routerLinkActive="active" role="button">Testing1</a>
                      <a class="btn  botonhome    mb-3 " routerLink="/backoffice/jobs" routerLinkActive="active" role="button">Testing2</a>
                    </div>         
                </div>
              </div>
                <!--<div class="contain bg-danger">-->
                <!--<img class="gear contain" src="https://upload.wikimedia.org/wikipedia/commons/1/13/Cog%2C_Web_Fundamentals.svg">-->

                <!--</div>-->
            </section>



            </section>
              <!-- 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="js/bootstrap.min.js"></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>

在响应式中发生的是按钮停留在屏幕的左侧而不是居中: enter image description here 因此,我尝试对这些按钮使用 d-block 和 mx-auto,它们在响应中正确居中。但是,在大屏幕上它们会分开: enter image description here

mx-auto 是否只能应用于或禁用特定视口(viewport)?

最佳答案

在所有宽度上应用 d-flex 而不是 d-sm-flex...

   <div class="col d-flex justify-content-center">
         <a class="btn botonhome mr-3 mb-3 " routerlink="/backoffice/job" routerlinkactive="active" role="button">Testing1</a>
         <a class="btn botonhome mb-3 " routerlink="/backoffice/jobs" routerlinkactive="active" role="button">Testing2</a>
   </div>

https://www.codeply.com/go/sJTHRXBK4M

关于html - bootstrap 4 在特定视口(viewport)禁用 mx-auto,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49824100/

相关文章:

javascript - 使用 PHP 解析 URL 并将其作为变量提供给 HTML

javascript - 将自定义 css 保持在 Angular 范围内

html - 如何让我的第二层导航出现在悬停时?

javascript - 如何创建后退/前进按钮?

python - Bootstrap 模板无法正常工作 Django

jquery - 如果不添加空的 <ul> 标签,nav-tabs 将无法工作

html - 将文本在缩略图的中间垂直对齐

html - CSS 网格 : align text in the same column

css - 在 Zend Framework 2 分页中更改样式

html - 使用任意元素格式化 CSS