Is there a better way of centering divs within a container? #399

Closed
rfkrocktk opened this Issue Oct 10, 2011 · 2 comments

Projects

None yet

2 participants

@rfkrocktk

I have the following setup:

<div class="container">
    <!-- content goes here -->
</div>

What I'm currently doing to center stuff horizontally is this:

<div class="container">
    <div class="row">
        <div class="span12" style="float:right">
            <div class="span7" style="float:left;">
                <!-- centered stuff goes here-->
            </div>
        </div>
    </div>
</div>

This seems like a lot of extra markup. Is there another class I could use to simply horizontally align a spanX within a container?

@mdo
Bootstrap member

If you want to center something within any element, you can assign special styles to it: margin: 0 auto;. If you want to center something within .row you can use the .offset* classes in the grid system to indent a column by some n number of columns.

@mdo mdo closed this Oct 10, 2011
@rfkrocktk

Here's a nice sample of centering using this method: http://jsfiddle.net/rfkrocktk/hcQ48/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment