Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap 3: How to center a block

It seems to me that the class center-block is missing from the bootstrap 3 style sheets. Am I missing something?

Its usage is described here, http://getbootstrap.com/css/#helper-classes-center

like image 211
DatsunBing Avatar asked Nov 03 '13 22:11

DatsunBing


People also ask

How do I center a block in Bootstrap?

Use class center-block to set an element to center.


Video Answer


2 Answers

It's new in the Bootstrap 3.0.1 release, so make sure you have the latest (10/29)...

Demo: http://bootply.com/91632

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>  <div class="row">      <div class="center-block" style="width:200px;background-color:#ccc;">...</div>  </div>
like image 155
Zim Avatar answered Oct 12 '22 17:10

Zim


It works far better this way (preserving responsiveness):

  <!-- somewhere deep start -->   <div class="row">     <div class="center-block col-md-4" style="float: none; background-color: grey">       Hi there!     </div>   </div>   <!-- somewhere deep end --> 

http://www.bootply.com/0L5rBI2taZ

like image 32
forker Avatar answered Oct 12 '22 18:10

forker