Last Updated: February 25, 2016
· thasmo

Align text next to a floated element

Sometimes it's necessary to align text next to a floated element e.g. an image element, without the text running underneath the floated element. Additionally the floated element maybe has a varying or dynamic width, which makes aligning text next to it a bit more complicated.

One simple solution is to use the CSS declaration overflow: hidden; on the element which needs to be aligned next to the floated one.


<img class="floated" alt="Floated image." />
<div class="aligned">Aligned division with text.</div>


img.floated {
    float: left;
    margin-right: 20px;

div.aligned {
    overflow: hidden;

overflow: auto; seems to work too.

Check out the snippet on jsfiddle.net

2 Responses
Add your response


Interesting! I wonder what makes it behave like that.

UPD. Found the answer! See The magic of “overflow: hidden”

over 1 year ago ·

This is a common pattern in the OOCSS circles known as a "media object".

over 1 year ago ·