Your selector is wrong. It should be:
.fl > div{ float:left; }
.fl div:nth-child(1){ position:relative; width:300px; height:300px; background-color:#066;}
.fl div:nth-child(2){ position:relative; width:300px; height:300px; background-color:#06F;}
.fl div:nth-child(3){ position:relative; width:300px; height:300px; background-color:#C30;}
<div class="fl">
<div class="bk">1</div>
<div class="bk">2</div>
<div class="bk">3</div>
</div>
By setting div:nth-child(1)
you are selecting div .fl
itself. If you want to select the children of .fl
, add .fl
to the nth-child()
selectors.
Explanation:
As div
is a generic selector, it will select all, regardless of the level:
<div class="fl"> nth-child(1)
<div class="bk">1</div> nth-child(1)
<div class="bk">2</div> nth-child(2)
<div class="bk">3</div> nth-child(3)
</div>
See that there are two nth-child(1)
, so div .fl
will have the same styles in:
div:nth-child(1){ position:relative; width:300px; height:300px; background-color:#066;}
So the div
s within .fl
will not stay side-by-side because div .fl
has the same width width
300px
%.