Explaining the behavior of floats, they follow these rules (refer to the specific guidelines):
- Floats are positioned as high as possible (but not exceeding line boxes with content created earlier in the source document).
- Left-floats are positioned as far left as possible, without overlapping preceding floats in document order.
- Right-floats are positioned as far right as possible, without overlapping previous floats in document order.
Therefore, if a left-float and a right-float can both fit on the same line, document order becomes irrelevant.
Otherwise, the float that appears first in document order will be displayed higher.
div {
margin: 30px 0;
border: 1px solid;
overflow: hidden;
counter-reset: float;
}
.wide { width: 75%; }
.left{ float: left; background: #ff0; }
.right{ float: right; background: #0ff; }
span:before { content: counter(float) ". "; counter-increment: float; }
<div><span class="left">Left</span><span class="right">Right</span></div>
<div><span class="right">Right</span><span class="left">Left</span></div>
<div><span class="left wide">Left</span><span class="right wide">Right</span></div>
<div><span class="right wide">Right</span><span class="left wide">Left</span></div>