http://twitter.github.com/bootstrap/scaffolding.html
I tried like all combinations:
<div class="row"> <div class="span7 offset5"> box </div> </div>
or
<div class="container"> <div class="row"> <div class="span7 offset5"> box </div> </div> </div>
changed span and offset numbers...
But I cant get a simple box perfectly centered on a page :(
I just want a 6-column-wide box centered...
did it with
<div class="container"> <div class="row" id="login-container"> <div class="span8 offset2"> box </div> </div> </div>
But the box is too wide, is there any way I can do it with span7 ?
span7 offset2
gives extra padding to the left span7 offset3
extra padding to the right...
You can do this by setting the display property to "flex." Then define the align-items and justify-content property to “center.” This will tell the browser to center the flex item (the div within the div) vertically and horizontally.
To horizontally center a block element (like <div>), use margin: auto; Setting the width of the element will prevent it from stretching out to the edges of its container.
Bootstrap's spans are floated to the left. All it takes to center them is override this behavior. I do this by adding this to my stylesheet:
.center { float: none; margin-left: auto; margin-right: auto; }
If you have this class defined, just add it to the span and you're good to go.
<div class="span7 center"> box </div>
Note that this custom center class must be defined after the bootstrap css. You could use !important
but that isn't recommended.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With