reverse the order of div's children
How can you reverse the order of a div's children with pure CSS?
For example:
I want
<div id="parent">
<div>A</div>
<div>B</div>
<div>C</div>
<div>D</div>
</div>
to be displayed as:
D
C
B
A
I've created a demo on JSfiddle: http://jsfiddle.net/E7cVs/2/
The modern answer is
#parent {
display: flex;
flex-direction: column-reverse;
}
A little bit tricky, but can work; just to give you the idea:
div#top-to-bottom {
position: absolute;
width:50px;
text-align: left;
float: left;
-webkit-transform: scaleY(-1);
transform: scaleY(-1);
}
div#top-to-bottom > div {
width: 50px;
height: 50px;
position: relative;
float: right;
display: block;
-webkit-transform: scaleY(-1);
transform: scaleY(-1);
}
mirror in the vertical axis both the container and the childs. The childs follow the inverted y axis of the container, but the children themselves are again head up.
demo
<style>
#parent{
display: -webkit-flex; /* Safari */
-webkit-flex-direction: row-reverse; /* Safari 6.1+ */
display: flex;
flex-direction: row-reverse;
}
</style>
100% work this code:
<style type="text/css">
.wrapper {
display: flex;
flex-direction: column-reverse;
}
</style>
<div class="wrapper">
<div class="main">top</div>
<div class="footer">bottom</div>
</div>