treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Apply margins to img depending its aligment?

  • 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.

  • 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;
    }