簡體   English   中英

如何使用自舉將按鈕對准中心?

[英]How to align a button to the center with bootstrap?

所以我的圖片是全屏的(頁腳除外),我的按鈕在中間。 一切正常,我的按鈕在中間,但是現在我開始使用引導程序並更改了按鈕,我的按鈕一直移到屏幕的左側,而不是中心在中間...有人嗎?解決方案?

注意:我嘗試做

 <div class="wrapper text-center">

仍然無法正常工作。

這是我拍攝的屏幕截圖: https : //gyazo.com/ce68d7b118156371ad02e7aa2a33ec2a

  <!DOCTYPE html>
    <html>
    <head>


        <title>
        project
        </title>
    <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="../css/main.css">
    </head>


    <body>




    <div class="wrapper">
            <button type="button" class="btn btn-primary">Login with Facebook</button>
        </div>

        <div class="footer"></div>

      <div class="download">Download</div>

    </body>
    </html>

然后...

    html,body{
      height:100%;
      width:100%;
      }
    .wrapper {
               display:flex;
               align-items:center; 
               width:100%;
               height:100%;
               background-image: url("../img/space.jpg");
               background-repeat:no-repeat;
               background-size:cover;

         }

        .button {
          width:100px;
          margin:auto;
        }

        .footer {

    padding-top: 200px;

        }

        .download {
          float: top;
        }

添加justify-content: center; .wrapper

 html, body { height: 100%; width: 100%; } .wrapper { display: flex; align-items: center; width: 100%; height: 100%; background-image: url("../img/space.jpg"); background-repeat: no-repeat; background-size: cover; justify-content: center; } .button { width: 100px; margin: auto; } .footer { padding-top: 200px; } .download { float: top; } 
 <!DOCTYPE html> <html> <head> <title> project </title> <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="../css/main.css"> </head> <body> <div class="wrapper"> <button type="button" class="btn btn-primary">Login with Facebook</button> </div> <div class="footer"></div> <div class="download">Download</div> </body> </html> 

您可以使用margin:0 auto;來簡單地做到這一點margin:0 auto;

.btn {
  margin:0 auto;
}

 html, body { height: 100%; width: 100%; } .wrapper { display: flex; align-items: center; width: 100%; height: 100%; background-image: url("../img/space.jpg"); background-repeat: no-repeat; background-size: cover; } .button { width: 100px; margin: 0 sauto; } .btn { margin:0 auto; } .footer { padding-top: 200px; } 
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <div class="wrapper"> <button type="button" class="btn btn-primary">Login with Facebook</button> </div> <div class="footer"></div> <div class="download">Download</div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM