I am looking for a CSS-only solution (if this is possible). So no changes to my HTML and no use of JavaScript. This is my HTML:
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis vitae commodi sunt voluptate ut ratione fugit iusto sequi. Voluptatibus provident, quo at vel vero praesentium ratione eligendi. Ab iure sequi quis est odio nihil a fugit labore, vero omnis cum.
</p>
<img src="http://www.fillmurray.com/284/196">
My HTML is part of a larger number of tags that also contain regular <p>
's that should look like regular paragraphs.
The only thing I could come up with was using a combination of inline-block
and float
:
p {
display: inline-block;
max-width: calc(100% - 284px);
}
img {
display: inline-block;
float: right;
}
The problem with this 'solution' though, is the text will not wrap around the image when the height of the text becomes greater than the height of the image. (See snippet below for an example).
Question: Without changing any of my HTML (ie: moving the img
tag above the p
tag), can this be done?
p {
display: inline-block;
max-width: calc(100% - 284px);
}
img {
display: inline-block;
float: right;
}
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis vitae commodi sunt voluptate ut ratione fugit iusto sequi. Voluptatibus provident, quo at vel vero praesentium ratione eligendi. Ab iure sequi quis est odio nihil a fugit labore, vero omnis cum. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis vitae commodi sunt voluptate ut ratione fugit iusto sequi. Voluptatibus provident, quo at vel vero praesentium ratione eligendi. Ab iure sequi quis est odio nihil a fugit labore, vero omnis cum. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis vitae commodi sunt voluptate ut ratione fugit iusto sequi. Voluptatibus provident, quo at vel vero praesentium ratione eligendi. Ab iure sequi quis est odio nihil a fugit labore, vero omnis cum. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis vitae commodi sunt voluptate ut ratione fugit iusto sequi. Voluptatibus provident, quo at vel vero praesentium ratione eligendi. Ab iure sequi quis est odio nihil a fugit labore, vero omnis cum.
</p>
<img src="http://www.fillmurray.com/284/196">
` tags, which not all have an image after them. Because there is no "previous" selector in CSS to target any
that comes before an image, I don't know how I can make regular paragraphs look regular. I will add this information to the question, I did not consider the relevance before.
– Dirk J. Faber Dec 22 '21 at 19:33` tags and `` tags.
– Dirk J. Faber Dec 22 '21 at 19:46