margin: 0 auto;
<div class="col-lg-1 col-centered"></div>
@DiegoFernandoMurilloValenci .clearfix wouldn't work in this case because it doesn't remove the float property on the elements (which is needed to center using margin: 0 auto), it just makes a container wrap any floated elements inside
@cheshireoctopus In that case what I would do is set up a .col-md-9.col-centered and then add a nested row and divide it equally in three columns with col-md-4 like this
If you want to center more then one column in a single line, see this answer stackoverflow.com/questions/28683329/
Note: With both techniques you could skip the .row element and have the column centered inside a .container but you would notice a minimal difference in the actual column size because of the padding in the container class.
Now you can add it to any column size at any screen size and it will work seamlessly with Bootstrap's responsive layout:
Since v3.0.1 Bootstrap has a built-in class named center-block that uses margin: 0 auto but is missing float:none. You can add that to your CSS to make it work with the grid system.
Thanks for the informative answer. Curious as how you could apply this if you had multiple odd-numbered colums within a row. For example: three div's with class col-md-3. How would you center those three divs?
The first approach uses Bootstrap's own offset classes so it requires no change in markup and no extra CSS. The key is to set an offset equal to half of the remaining size of the row. So for example, a column of size 2 would be centered by adding an offset of 5, that's (12-2)/2.
There are two approaches to centering a column <div> in Bootstrap 3:
You can center any column size by using the proven margin: 0 auto; technique, you just need to take care of the floating that is added by Bootstrap's grid system. I recommend defining a custom CSS class like the following:
can't use this on a column, because no float:none;
i think that there is no float:none in the center-block rule because there is a clearfix independent rule that you can add to elements for clearing floats.