center a row using Bootstrap 3

后端 未结 13 1399
长发绾君心
长发绾君心 2020-12-29 18:08

How to center a row (12 column) in Bootstrap 3 ? I do not want to use the offset

I am using this way but not worked.

相关标签:
13条回答
  • 2020-12-29 18:37

    I use this peace of code and I have successeful

    <div class="row  center-block">
    <div style="margin: 0 auto;width: 90%;"> 
        <div class="col-md-12" style="top:10px;">
        </div>
        <div class="col-md-12" style="top:10px;">
        </div>
     </div>
    

    0 讨论(0)
  • 2020-12-29 18:39

    Why not using the grid system?

    The bootstrap grid system consist of 12 columns, so if you use the "Medium" columns it will have a 970px width size.

    Then you can divide it to 3 columns (12/3=4) so use 3 divs with "col-md-4" class:

    <div class="col-md-4"></div>
    <div class="col-md-4"></div>
    <div class="col-md-4"></div>
    

    Each one will have 323px max width size. Keep the first and the last empty and use the middle one to get your content centerd:

    <div class="col-md-4"></div>
    <div class="col-md-4">
       <p>Centered content.</p>
    </div>
    <div class="col-md-4"></div>
    
    0 讨论(0)
  • 2020-12-29 18:40

    Add this to your css:

    .row-centered {
       text-align:center;
    }
    
    
    .col-centered {
       display:inline-block;
       float:none;
       /* reset the text-align */
       text-align:left;
       /* inline-block space fix */
       margin-right:-4px;
    }
    

    Then, in your HTML code:

        <div class=" row row-centered">
            <div class="col-*-*  col-centered>
               Your content
            </div>
        </div>
    
    0 讨论(0)
  • 2020-12-29 18:42

    We can also use col-md-offset like this, it would save us from an extra divs code. So instead of three divs we can do by using only one div:

    <div class="col-md-4 col-md-offset-4">Centered content</div>
    
    0 讨论(0)
  • 2020-12-29 18:45

    Simply use text-center class

     <div class="row">
         <div class="col-md-12">
              <h3 class="text-center">Here Comes your Text</h3>
         </div>
     </div>
    
    0 讨论(0)
  • 2020-12-29 18:46

    Try this, it works!

    <div class="row">
        <div class="center">
            <div class="col-xs-12 col-sm-4">
                <p>hi 1!</div>
            </div>
            <div class="col-xs-12 col-sm-4">
                <p>hi 2!</div>
            </div>
            <div class="col-xs-12 col-sm-4">
                <p>hi 3!</div>
            </div>
        </div>
    </div>
    

    Then, in css define the width of center div and center in a document:

    .center {
        margin: 0 auto;
        width: 80%;
    }
    
    0 讨论(0)
提交回复
热议问题