Using position: absolute for a child of a flexbox does not make much sense, as it simply invalidates the flex-child status of that element. In your example, two children are simply placed as they would be without a flex container. Since both of them do not have upper / left / right / lower settings, they are both located in the upper left corner by default, above each other in the order in which they appear in the code - the last one above the previous one.
order parameters no longer have any effect, since these elements are no longer flexible elements, and order applies only to "real" flexible elements.
Look at my snippet: I just changed the first and second div (leaving all your other code as it is), so now the second div is on top of the first.
.container {display: flex} .child1, .child2 {position: absolute} .child1 {background: red; order: 2;} .child2 {background: yellow; order: 1;}
<div class="container"> <div class="child2">this is an second</div> <div class="child1">this is a first</div> </div>
ADD AFTER COMMENTS from Michael_B:
Here is another snippet, with two additional βrealβ flexible elements. When all siblings have order parameters, this affects the "real" flexible elements, but not the absolutely positioned elements that simply fit on top of each other in the order in which they appear in the code, as well as on top of the flexible elements.
.container {display: flex; } .child1, .child2 {position: absolute; } .child1 {background: red; order: 2;} .child2 {background: yellow; order: 4;} .child3 { border: 1px solid green; order: 3;} .child4 { border: 1px solid blue; order: 1;}
<div class="container"> <div class="child2">this is an second</div> <div class="child1">this is a first</div> <div class="child3">this is a real flex-item 3</div> <div class="child4">this is a real flex-item 4</div> </div>
Johannes
source share