
A floating image takes away horizontal space from the text that flows around it. In fixed width layouts, you can check that the space left for the text is enough to create a decent looking column, safe in the knowledge that everyone else will see the same thing.
In a fluid layout, however, you have no such guarantee. If a user views your site on a smaller device, the horizontal space left for the text may only fit a word or two per line. Such a narrow column of text doesn’t just look ugly; it is also brittle. A sentence containing a long word will split when the long word moves down below the floating image, leaving behind it dead empty space mid-sentence.
The elusive minimum paragraph width
To solve the problem of too narrow paragraphs, we need a way to implement a minimum paragraph width. If the space left by the floating image is below this width, then the whole paragraph moves down underneath the image.

Intuitively, the following CSS seems to fit the bill:
p {
min-width: 10em;
/* For demonstration */
border: 1px solid red;
}
However, this has no effect. The image floats above the paragraph, and thus doesn’t reduce the paragraph’s ‘official’ width. Meanwhile, the text within the paragraph dutifully moves aside to make room for the floating image, and so the problem remains.
The media query solution for known image widths

If your images (or other floating content) share a fixed and predefined width, then you can use CSS3 media queries to disable the floating at screen sizes that are too narrow to fit both an image and a text column side by side.
This solution will of course only work on browsers that support CSS media queries. For other browsers, the solution degrades to the original problem.
@media screen and (max-width: 400px) {
img {
float: none;
}
}
General case solution using pseudo element
The media query solution doesn’t work when the floating elements have arbitrary widths, nor is it very elegant.

A better solution is to give every paragraph an invisible CSS pseudo-element with the desired minimum paragraph width. If there isn’t enough space to fit this pseudo-element, then it will be pushed down underneath the image, taking the paragraph with it.
This solution is supported by most browsers. On older browsers, the solution degrades gracefully to the original problem.
p:before {
content: "";
width: 10em;
display: block;
overflow: hidden;
/* For Demonstration */
border: 1px solid green;
}
The pseudo element’s green border
is there for demonstration purpose only. It is not required for the solution and you should remove it in your code. The pseudo element will then take no vertical space at all.
Demo & Download
About the Author
Gustav Andersson is the author behind The Modern Nomad, a site exploring nomadic lifestyles which frees people to live and work anywhere, anytime. He is a tango-dancing, steer-wrestling, grammar-loving burner who wants to inspire you to consider a life without an address.
You could also just use overflow: hidden on the paragraph with a minimum width to establish a new block formatting context, which should make it behave like you want it to.
Take out the min-width to see why this works (it forces the paragraph not to fall behind the floated content). I love block formatting contexts, and this property of them is really under-used.
But that doesn’t wrap properly.
If you write more text so that the paragraph is taller than the floated image, it doesn’t start to flow underneath the image; it just continues in a constant-width vertical column.
Interesting solution regarding the pseudo element.
I’ve used the float:none before and hadn’t thought about the other one. Will try it next time.
Great idea!
I’m on mobile, so I can’t test, but I believe that and adjacent selector could be useful here: “img + p:before”.
Great advice, will try it out very soon.
Nice tip. Worth trying
Nice, very clever.
This works great if you keep your img tag before or after the paragraph. If you put an image in the midst of it, then the paragraph won’t maintain its minimum width.
This only works if we float the image to the right. What about float left? Should we also have to float the pseudo element to the right, or move the pseudo element to the right with absolute position? I think media queries are still the best solution, we can simply get the algnment class from the images, then disable the float, or just make the pseudo element via media queries:
Hi,
Do common email clients support this css trick? Could this be a way to avoid using tables?
Great tip. I’m sure i’ll be using this a lot.
You could also give the image a max width… Eg 50% of a P.
you just gave me a one great tip, i’m sure i’m gona use this
This doesn’t work for me in FF 11.0 without a top border (border-top:1px solid transparent) on the P tag — it reverts to the original problem.
It works as described in IE8, I have not had a chance to test other browsers.
Nice post man! I personally use min-width for just about everything now, lol. RWD all the way!
What we really need is breaking lines with hyphens. Wonder when webbrowsers get advanced enough for that.
A very helpful workaround! Thank you for the in-sight, I am sure this will come in useful.
Nice post – thanks for sharing :)