Grow your CSS skills. Land your dream job.

Apply margins to img depending its aligment?

  • # December 3, 2012 at 4:36 pm

    Howdy.

    I would like to add margins to images depending on their alignment. For example; if an image is aligned or floated to the left, I would like to add margin to its right and bottom only. If aligned to the right, apply margins to left and bottom.

    Is that possible with css? or do I need some javascript in order to perform this task?

    Thanks again for your time and input.

    # December 3, 2012 at 4:51 pm

    You could do this with classes, then apply the class to the floated images.

    .right {
    float: right;
    margin: 0 0 1em 1em;
    }

    .left {
    float: left;
    margin: 0 1em 1em 0;
    }

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

You must be logged in to reply to this topic.

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