Grow your CSS skills. Land your dream job.

how do i use the auto selector to place an image tag in the middle of a DIV tag

  • # September 25, 2012 at 2:00 am

    hi everyone.

    i want to place an image in the middle of a “div tag”.

    i tried using the auto selector to do this but it does not work.

    so, i was wondering, does the auto selector work with Img tag. i tried the following;


    .picmiddle img {
    margin:0 auto 0 auto;

    }
    # September 25, 2012 at 3:55 am

    Images are inline elements by default. Set display block then margin: 0 auto to center it.

    # September 25, 2012 at 11:21 am

    ah. that is great. thanks HugoGiraudel.

    one question; do you mean i should margin 0 first and then subsquently use the auto

    warm regards

    Andreea

    # September 25, 2012 at 11:31 am

    He means that


    margin: 0 auto;

    is the same as


    margin:0 auto 0 auto;

    but add this


    display:block;

    Like this: http://codepen.io/Paulie-D/pen/grosf

    # September 25, 2012 at 11:47 am

    wow. great. thanks guys.

    i really appriciate this

    # September 25, 2012 at 1:10 pm

    I guess I wasn’t clear enough. Sorry. :)

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

You must be logged in to reply to this topic.

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