How to set "smart" margins of image depending on its alignment? My website has pages in Rich Text Format, powered by django-ckeditor. When the user inserts an image (or a figure element with an image), he can align it right or left.
<figure class="image" style="float:right">
<img height="180" width="280" src="/media/about/team/images.jpeg">
<figcaption>Hello world!</figcaption>
</figure>
I want the image to be nicely aligned to the outer side of the text block. This means, the outer margin and padding should be 0, and the inner margin should be, say 1em.
Is it possible to do this with CSS styles? I think I met it on one website, but can't remember where.
The logic should be following: if the element already has style "float: left", the left margin is 1em, right margin 0, and vice versa.
If you know that the
float:leftorfloat:rightis in the HTML markup then you can use that as your selector for further styling. So: