Is there any way to make a fluid layout, where if a floating element doesn't fit, it would move to the left of the next line? Here is a picture of what I'm trying to achieve:
If there is space for both green and right elements, the red element floats to the right.
If there is not enough space (either green element is long, or screen is too small), the red element should wrap and align itself to the left.
This is what I currently have: fiddle
As you can see, the green element keeps aligning 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;
}