Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I center element within a container while keeping them vertically aligned?

Not really sure how to properly title this. It is best explained with images. I am trying to keep the items centered, but when there is too many to fit properly on one line, the new line should be aligned with the item above it, not centered within the container.

I am trying to achieve this:

enter image description here Instead of this:

enter image description here

Here is my JSfiddle:

http://jsfiddle.net/6kwzy6La/

And my HTML:

<div class="container2">
    <div class="content">

        <div id="box">
            <p> Some text goes here </p>
        </div>

        <div id="box">
            <p> Some text goes here </p>
        </div>

        <div id="box">
            <p> Some text goes here </p>
        </div>

        <div id="box">
            <p> Some text goes here </p>
        </div>

        <div id="box">
            <p> Some text goes here </p>
        </div>

    </div>
</div>
like image 544
Celestriel Avatar asked Jan 20 '26 04:01

Celestriel


1 Answers

http://jsfiddle.net/6kwzy6La/

Container1
{
text-align: center;
}

Container2
{
text-align: left;
}
like image 194
gr3g Avatar answered Jan 22 '26 18:01

gr3g



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!