How do I center a div of one column size within the container (12 columns) in Twitter Bootstrap 3.
Please see the starter fiddle.
<body class="container">
<div class="col-lg-1 col-offset-6 centered">
<img data-src="holder.js/100x100" alt="" />
</div>
</body>
So, I want a div
, with a class centered
to be centered within the container. I may use a row if there are multiple divs, but for now I just want a div with size of one column centered within the container (12 columns).
I am also not sure the above approach is good enough as the intention is not to offset the div
by half. I do not need free spaces outside the div
and the contents of the div
shrink in proportion. I want to empty space outside the div to be evenly distributed (shrink till the container width == one column).
This works. A hackish way probably, but it works nicely. It was tested for responsive (Y).
You can use the very flexible solution flexbox to your Bootstrap.
can center your column.
Check out flex.
To center more than one column in a Bootstrap row - and the number of cols are odd, simply add this
css
class to all the columns in that row:So in your HTML you have something like:
I suggest simply to use the class
text-center
:Just set your one column that displays content to col-xs-12 (mobile-first ;-) and configure the container only to control how wide you want your centred content to be, so:
For a demo, see http://codepen.io/Kebten/pen/gpRNMe :-)
Bootstrap version 3 has a .text-center class.
Just add this class:
It will simply load this style:
Example: