Problem Description
I have this (quite common) problem. If I float an image, I can give margins to it so it wraps around the image with some space. So, if I do this:
.alignleft {
float: left;
margin: 0 15px 15px 0;
}
<img class="alignleft" src="https://via.placeholder.com/350x150" alt="" />
<p>Li Europan lingues es membres del sam familie. <strong>Lor separat existentie es un myth.</strong> Por scientie, musica, sport etc, litot Europa usa li sam vocabular. Li lingues differe solmen in li grammatica, li pronunciation e li plu commun vocabules.
<em>Omnicos directe al desirabilite de un nov lingua franca:</em> On refusa continuar payar custosi traductores. At solmen va esser necessi far uniform grammatica, pronunciation e plu commun paroles.</p>
<p>Li Europan lingues es membres del sam familie. <strong>Lor separat existentie es un myth.</strong> Por scientie, musica, sport etc, litot Europa usa li sam vocabular. Li lingues differe solmen in li grammatica, li pronunciation e li plu commun vocabules.
<em>Omnicos directe al desirabilite de un nov lingua franca:</em> On refusa continuar payar custosi traductores. At solmen va esser necessi far uniform grammatica, pronunciation e plu commun paroles.</p>
And it works fine, of course.... as long as the image is at the top of the element. But if I add it in the middle of the text, this is what will happen:
.alignleft {
float: left;
margin: 0 15px 15px 0;
}
<p>Li Europan lingues es membres del sam familie. <strong>Lor separat existentie es un myth.</strong> Por scientie, musica, sport etc, litot Europa usa li sam vocabular. Li lingues differe solmen in li grammatica, li pronunciation e li plu commun vocabules.
<img class="alignleft" src="https://via.placeholder.com/350x150" alt="" /> <em>Omnicos directe al desirabilite de un nov lingua franca:</em> On refusa continuar payar custosi traductores. At solmen va esser necessi far uniform grammatica, pronunciation
e plu commun paroles.</p>
<p>Li Europan lingues es membres del sam familie. <strong>Lor separat existentie es un myth.</strong> Por scientie, musica, sport etc, litot Europa usa li sam vocabular. Li lingues differe solmen in li grammatica, li pronunciation e li plu commun vocabules.
<em>Omnicos directe al desirabilite de un nov lingua franca:</em> On refusa continuar payar custosi traductores. At solmen va esser necessi far uniform grammatica, pronunciation e plu commun paroles.</p>
just in case, here's the issue:
Since it has margin:0
, the image has no space above. Obviously, I could add margin:15px
and be a happy camper, but then I'd have a 15px space above the image when it is the first element.
I tried using .alignleft:not(:first-line)
but it didn't work, not even adding the image inside the p
tag, so I'm out of ideas
The Question
So, basically, my question is: is it possible to make these margins behave in a conditional way?