I thought this would be (relatively) easy, but from the answers it seems harder than I anticipated.
Perhaps even impossible!
GOAL
I'd like to have a large list of div elements that can arbitrarily be assigned a .left
or .right
class.
All the .left
divs should stack up underneath each other on the left hand side, the .right
divs should stack up underneath each other on the right hand side. The number of divs in each class is arbitrary.
THREE CONDITIONS
The height of each div will not be known in advance
I would like them to stack up underneath each other on the assigned side, regardless of how many divs are present, what order they appear in, and how many are assigned to either side.
I don't want to use a 'wrapper' div as some have suggested. This is because the solution must cater for random quantity and ordering of
.left
and.right
divs (see example below).
Ideally I'd like it to be a pure html / css solution, as backwards compatible as possible - though I realise this may prove unrealistic.
SAMPLE HTML
<div class="left">left one</div>
<div class="left">left two</div>
<div class="right">right one</div>
<div class="left">left three</div>
<div class="right">right two</div>
<div class="right">right three</div>
<div class="left">left four</div>
<div class="right">right four</div>
<div class="right">right five</div>
<div class="left">left five</div>
<div class="right">right six</div>
<div class="right">right seven</div>
UPDATE
After so many answers I'm impressed by the range of answers/techniques, but none of them quite meet all of the conditions.
Hence I'm staking a quarter of my meagre reputation on trying to get a solid solution!
UPDATE 2
It seems that my original goal is undoable. Therefore I have not marked any as the answer, although having put up a bounty I awarded it to Josh who gave me the best way of (almost) achieving that, along with great explanations of the css he used.
Thanks everyone for your help and ideas.