I was working on a jsfiddle in an attempt to provide an answer to this question, but ran into some unexpected behaviour.
- I have a list of floated boxes (
float:left), flowing over multiple lines. - If I add
position:absoluteto a box on the first line, it stays in its position (as expected), but only in Chrome (not FF). - If I add
position:absoluteto a box on second/third/… line, the box is positioned outside the containing div. If Iadd top:0andleft:0to this box, it is positioned in the top left corner of the containing div. This happens in all browsers.
As I have no idea how to explain/fix this behaviour, I was wondering if anyone else had an idea what’s going on?
Based off this experiment, the elements are being positioned to the top of the wrapper as expected, but they are moving “after” the floated elements, which are all positioning to the left as they should. In other words, the absolute is making them become “last” in the list because of the float left.
It seems to do the opposite with
float: rightas seen here.Somehow, the float positioning (in the left scenario) is making the absolute element that is “out of flow” be pushed after the floats and this is pushing the elements “outside” your box when the width is 100px. Note how with less elements the absolute just falls in behind the floats, as seen here.