Bootstrap Center align a div horizontally

前端 未结 3 1722
猫巷女王i
猫巷女王i 2021-01-11 18:04

I have tried simple login page for a sample. But am unable to align the fields to center. h:commandButton is aligned to center. but rest of the fields are does

相关标签:
3条回答
  • 2021-01-11 18:14

    simplest way is to add a custom class .col-center from your side to it

    .col-center{
      margin:0 auto;
    }
    

    why this way?? because BS has the methodology of offset but it has a drawback as it only works for even column sizes, so only .col-X-2, .col-X-4, col-X-6, col-X-8 and col-X-10 are supported.

    Must do : just make sure that whichever div you want to center, has a div width mentioned to it.....col-center will do rest of job

    0 讨论(0)
  • 2021-01-11 18:24

    As of 2019 Oct, class="center-block" is dropped and "mx-auto" is introduced for the same purpose in current bootstrap version.

    <div class="mx-auto bg-warning" style="width:150px">Centered</div>
    
    0 讨论(0)
  • 2021-01-11 18:26

    To center a block level element horizontally in bootstrap use Use center-block class.

    For example:

    <div class="center-block">...</div>
    
    0 讨论(0)
提交回复
热议问题