Grow your CSS skills. Land your dream job.

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?

    Thanks

    # 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".

    mat
    # 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

    Code:
    .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.

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