Bootstrap 4 Center Vertical and Horizontal Alignment

前端 未结 11 2811
借酒劲吻你
借酒劲吻你 2020-11-21 04:37

I have a page where only form exists and I want form to be placed in the center of the screen.

相关标签:
11条回答
  • 2020-11-21 04:53

    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
        <div class="col-12 border border-info">
              <div class="d-flex justify-content-center align-items-center" style="height: 100px">
                  <a href="#" class="btn btn-dark">Transfer</a>
                  <a href="#" class="btn btn-dark mr-2 ml-2">Replenish</a>
                  <a href="#" class="btn btn-dark mr-3">Account Details</a>
              </div>
        </div>

    0 讨论(0)
  • 2020-11-21 05:01

    From the doc (bootsrap 4):

    https://getbootstrap.com/docs/4.0/utilities/flex/#justify-content

    .justify-content-start
    .justify-content-end
    .justify-content-center
    .justify-content-between
    .justify-content-around
    .justify-content-sm-start
    .justify-content-sm-end
    .justify-content-sm-center
    .justify-content-sm-between
    .justify-content-sm-around
    .justify-content-md-start
    .justify-content-md-end
    .justify-content-md-center
    .justify-content-md-between
    .justify-content-md-around
    .justify-content-lg-start
    .justify-content-lg-end
    .justify-content-lg-center
    .justify-content-lg-between
    .justify-content-lg-around
    .justify-content-xl-start
    .justify-content-xl-end
    .justify-content-xl-center
    .justify-content-xl-between
    .justify-content-xl-around
    
    0 讨论(0)
  • 2020-11-21 05:03

    You need something to center your form into. But because you didn't specify a height for your html and body, it would just wrap content - and not the viewport. In other words, there was no room where to center the item in.

    html, body {
      height: 100%;
    }
    .container, .row.justify-content-center.align-items-center {
      height: 100%;
      min-height: 100%;
    }
    
    0 讨论(0)
  • 2020-11-21 05:05

    This is working in IE 11 with Bootstrap 4.3. While the other answers were not working in IE11 in my case.

     <div class="row mx-auto justify-content-center align-items-center flex-column ">
        <div class="col-6">Something </div>
    </div>
    
    0 讨论(0)
  • 2020-11-21 05:08

    flexbox can help you. info here

    <div class="d-flex flex-row justify-content-center align-items-center" style="height: 100px;">
        <div class="p-2">
         1
        </div>
        <div class="p-2">
         2
        </div>
    </div>
    
    0 讨论(0)
  • 2020-11-21 05:14

    Use This Code In CSS :

    .container {
        width: 600px;
        height: 350px;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        display: inline-flex;
    }
    
    0 讨论(0)
提交回复
热议问题