On my html page I have this situation:
<div1><div2><div3><div4><div5><div6><div7><div8><div9>…
Just left floating divs shown one after another. All of them have CSS style float:left
I would like to achieve this result:
<div1><div2>
<div3><div4><div5><div6><div7>
<div8><div9>...
Basically, I would like to break flow on div3 and div8 (or on any div I wish) by telling it to start in new line. All other elements should follow after div that goes into new line. I tried using clear:left or clear:left on div3 or div8 , but it didn’t work. Div would go to new line, but all others would remain where they were, producing undesired result:
<div1><div2><div4><div5><div6><div7><div9>
<div3>
<div8>...
Is there any nice and simple solution here? Thanks.
For the love of god… don’t introduce any additional
divsinto your markup.clear:leftworks, if your design is correct. (you do know HTML has a whole selection of block-level elements to choose from) Using them might make your targeting a little easier…CSS
HTML
fiddle: http://jsfiddle.net/d68pr/
EDIT
Here’s one that doesn’t require any IDs, classes, OR extra
div-itushttp://jsfiddle.net/TMxSE/
** warning **
nth-childmay not be available in some browsers. Check your traffic statistics to be sure IE8, and below are a very small percentage of your user-base. Or that those users’ experiences are acceptable.