Is there a way to make a liquid layout where, if a floating element does not fit, it moves to the left of the next line? Here is a picture of what I'm trying to achieve:

If there is room for the green and right elements, the red element floats to the right.
If there is not enough space (either the green element is long or the screen is too small), the red element should wrap and align itself to the left.
This is what I have now: fiddle
As you can see, the green element continues to align to the right after wrapping.
code:
<div class="wrap"> <div class="red">long long long long text</div> <div class="green">needs to align to the left</div> </div> .red { display: inline-block; border-color: red; } .green { float: right; width: 80px; border-color: green; }
source share