HTML:
<div class="bigdiv">
<div class="div1">div 1</div>
<div class="div2">div 2</div>
<div class="div3">div 3</div>
</div>
CSS:
.bigdiv {
display:table;
width:100%;
}
.div1 {
display: table-row-group;
}
.div2 {
display: table-footer-group;
}
.div3 {
display: table-header-group;
}
The result will be:
div 3
div 1
div 2
And for those pesky early versions of Internet Explorer... Source
Old browsers IE6 and IE7 do not support CSS properties of display: table family.
Also, IE8 has a dynamic rendering bug that appears in some cases: if a block to move contains preudo-table elements (display: table*) (this is the only buggy case noticed currently), some pseudo-table cells (such cells as well as cells count are different each time the page is reloaded) may disappear randomly when the page is initially rendered.
So, for IE8 and lower, we can override CSS rules that make blocks tably, and additionally move blocks to required positions in DOM tree of HTML document with JavaScript instead of CSS:
/**
* Reorders sibling elements in DOM tree according to specified order.
* @param {Array} elems Sibling elements in desired block order.
*/
function reorderElements(elems) {
var count = elems.length;
if (!count) {
return;
}
var parent = elems[0].parentNode;
for (var i = count - 1; i >= 0; i--) {
parent.insertBefore(elems[i], parent.firstChild);
}
}
// If IE8 or lower
if (document.all && !document.addEventListener) {
var blocks = [
document.getElementById('div3'),
document.getElementById('div2'),
document.getElementById('div1')
];
reorderElements(blocks);
}