The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

center within div

  • # January 14, 2010 at 6:24 pm

    this might be a stupid question, but how can I center a photo in a div without using margins?
    Is there a rule for other elements like the ‘text-align’ rule?


    # January 14, 2010 at 7:26 pm

    you can use relative positioning or the "margin: 0 auto" trick

    # January 14, 2010 at 10:19 pm

    Thanks, though I tried this and it didn’t work.

    I tried it with all positioning:relative and absolute

    # January 14, 2010 at 11:49 pm

    That may be the problem. Try "position: relative" instead of "positioning:relative".

    # January 15, 2010 at 5:21 am

    I normally have this is my reset stylesheet for generic classes i want to use wsuch as img_center

    .img_center {
    position: relative;
    display: block;
    padding: 0;
    margin: 0 auto;
    # January 15, 2010 at 11:55 am

    You can also use "text-align: center;"

    # January 15, 2010 at 8:05 pm

    I was using ‘position’ not ‘positioning’. I just used the word positioning in the post.

    I need to center horizontally, though not vertically.
    This looks like it will center both ways.

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

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed