How can I dynamically adjust the margins of an image based on its alignment? My website uses Rich Text Format pages with django-ckeditor. Users can align images to the right or left when inserting them.
<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 align nicely with the text block's outer edge. This means that the outer margin and padding should be 0, while the inner margin should be around 1em.
Can this be achieved using CSS styles? I vaguely recall seeing it on a website before, but I can't remember where.
The idea is that if the element already has a style of "float: left," then the left margin should be 1em and the right margin should be 0, and vice versa.