I'm trying to follow a very basic example. Using the starter page and the grid system, I was hoping the following:
<div class="row">
<div class="span12">
<h1>Bootstrap starter template</h1>
<p>Example text.</p>
</div>
</div>
...would produce centered text.
However, it still appears on the far left. What am I doing wrong?
I tried two ways, and it worked fine to center the div. Both the ways will align the divs on all screens.
Way 1: Using Push:
Way 2: Using Offset:
Result:
Explanation
Bootstrap will designate to the left, the first column of the specified screen-occupancy. If we use offset or push it will shift the 'this' column by 'those' many columns. Though I faced some issues in responsiveness of offset, push was awesome.
If you are using Bootstrap 2.0+
This can make the div centered to the page.
Simply use a class, text-center, for the div or tag which you want. I think it may work fine. It is a Bootstrap class for text align center.
Here are some text alignment Bootstrap classes:
You can use any one of the below types
text-center
.style = "text-align:center"
.Use a column offset:
Example:
<div class="col-md-offset-6 col-md-12"></div>
I guess most of the people here are actually searching for the way to center the whole
div
and not only the text content (which is trivial…).The second way (instead of using text-align:center) to center things in HTML is to have an element with a fixed width and auto margin (left and right). With Bootstrap, the style defining auto margins is the "container" class.
Take a look here for a fiddle: http://jsfiddle.net/D2RLR/7788/