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?
As of February 2013, in some cases, I add a "centred" class to the "span" div:
and to CSS:
The reason for this is because the span* div's get floated to the left, and the "auto margin" centering technique works only if the div is not floated.
Demo (on JSFiddle): http://jsfiddle.net/5RpSh/8/embedded/result/
JSFiddle: http://jsfiddle.net/5RpSh/8/
For Bootstrap version 3.1.1 and above, the best class for centering the content is the
.center-block
helper class.This is for Text Centering (which is what the question was about)
For other types of content, see Flavien's answer.
Update: Bootstrap 2.3.0+ Answer
The original answer was for an early version of bootstrap. As of bootstrap 2.3.0, you can simply give the div the class
.text-center
.Original Answer (pre 2.3.0)
You need to define one of the two classes,
row
orspan12
with atext-align: center
. See http://jsfiddle.net/xKSUH/ or http://jsfiddle.net/xKSUH/1/Do not use container-fluid in the main.
If you use Bootstrap 3, it also has built-in CSS class named .text-center. That's what you want.
Please see the example in jsfiddle. http://jsfiddle.net/ucheng/Q4Fue/
You need to adjust with the
.span
.Example: