When you float only .left-sidebar
, what happens is that it floats against the content of .main
only. The .main
element itself is positioned as if .left-sidebar
were not there at all — that is, .left-sidebar
has been taken out of the normal flow that .main
participates in.
When you float both elements, what happens is that .left-sidebar
floats against .main
itself. The result is that the two boxes stack against each other side by side. The .main
element is positioned following the float of .left-sidebar
because both of them are floating. The content within .main
is unaffected by the .left-sidebar
float.
Section 9.5.1 of the spec has very concise descriptions of the float
property and its values. Specifically,
left
The element generates a block box that is floated to the left. Content flows on the right side of the box, starting at the top (subject to the 'clear' property).
It also specifies in detail how exactly floats should interact with other content and other floats. There are several rules but only the second one applies to your example (it basically means "left-floating boxes must stack against one another, if not horizontally then vertically"):
Here are the precise rules that govern the behavior of floats:
- ...
- If the current box is left-floating, and there are any left-floating boxes generated by elements earlier in the source document, then for each such earlier box, either the left outer edge of the current box must be to the right of the right outer edge of the earlier box, or its top must be lower than the bottom of the earlier box. Analogous rules hold for right-floating boxes.
- ...