Grow your CSS skills. Land your dream job.

[Solved] Center 2 DIVS side by side in wrapper?

  • # March 8, 2013 at 1:54 am

    Hello,

    I’m having issues with what appears to be an extremely simple problem. I just can’t seem to wrap my head around this for some reason. Essentially…Im trying to position two centered divs, side by side in a wrapper. I’ve been able to center the divs, but they are stacking instead of sitting next to each other. I’ve tried using float:left and display:inline-block…neither solving the issue. If anyone can suggest a solution for this…I’d be ever so grateful.

    Code sample: http://jsfiddle.net/TZj6B/6/

    Thank You

    # March 8, 2013 at 2:06 am

    Check this[ pen](http://codepen.io/alex13/pen/dJKcu “”).

    # March 8, 2013 at 2:17 am

    @codegraphics

    Awesome… and thank you

    # March 8, 2013 at 2:18 am

    Here is a better version of @CodeGraphics code but without the extra html and unnecessary css. You dont need so much code for a simple thing.

    Simply put, if you have a div, and the elements inside are set to “display:inline-block” then you can just use “text-align:center” to center them inside. Then reset the “text-align:left” inside the box.

    [http://cdpn.io/dJKcu](http://cdpn.io/dJKcu “Code”)

    # March 8, 2013 at 2:42 am

    @noahgelman

    your pen seemed to be the same as posted above…I’m assuming this is what you were referring to…

    http://codepen.io/anon/pen/CGwgn

    # March 8, 2013 at 2:56 am

    I forked it further (to clean up and to simplify it): http://codepen.io/Merri/pen/vHJtf

    # March 8, 2013 at 3:40 am

    Here is a flexbox version (modern browsers only): http://jsfiddle.net/wqD62/.

    # March 8, 2013 at 1:47 pm

    @Rugg

    Yeah, sorry for wrong link.

    Here below is a much more optimized version. Less CSS.

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘[Solved] Center 2 DIVS side by side in wrapper?’ is closed to new replies.

*May or may not contain any actual "CSS" or "Tricks".