htmlcsstwitter-bootstraptwitter-bootstrap-3

Bootstrap: two column centered


I'm trying to have a two-column centered layout with Bootstrap 3.1. I've read this: How do I center a Bootstrap div with a 'spanX' class?, but the content is stil aligned to the left. Here is my HTML:

<div class="row">
<div class="center">

    <div class="col-lg-3 gauche">
    Left div
    </div>

    <div class="col-lg-5 corps">
    Right div
    </div>

</div>
</div>

And my CSS:

body
{
    padding: 0;
    margin: 0;
}
.corps
{
    background-color: white;
}
.contenu
{
    margin-top: 5em;
    margin-bottom: 1em;
    background-color: white;
    padding: 1.2em;
    padding-left: 1.5em;
}
.center
{
    float: none;
    margin-left: auto;
    margin-right: auto;
}
.gauche
{
    background-color: #e6e6e6;
    min-height: 200px;
}

Result is here: https://i.sstatic.net/6G2Rq.png


Solution

  • Add a container, remove the center div and add two blank col-lg-2 on either side so it adds up to 12 columns:

    <div class="container">
     <div class="row">
      <div class="col-lg-2">
      </div>
      <div class="col-lg-3 gauche">
      Left div
      </div>
    
      <div class="col-lg-5 corps">
      Right div
      </div>
      <div class="col-lg-2">
      </div>
     </div>
    </div>