For example, without js - flex ( oreder - sets the order of location):
#block_1 { height:50px; background:red; } #block_2 { height:35px; background:green; } .row { display: flex; flex-flow: column nowrap; } @media screen and (min-width: 992px){ #block_2 { order: 1; } #block_1 { order: 2; } }
<div class="row"> <div id="block_1">Блок 1</div> <div id="block_2">Блок 2</div> </div>
Cross-browser flex . By the way, bootstrap4 and in the grid already uses flex /
Option with table :
#block_1>div { height:50px; background:red; } #block_2>div { height:35px; background:green; } @media screen and (min-width: 992px) { .row { display: table; width: 100%; } #block_1 { display:table-footer-group; } #block_2 { display:table-header-group; } }
<div class="row"> <div id="block_1"> <div> Блок 1 </div> </div> <div id="block_2"> <div> Блок 2 </div> </div> </div>
Option with jquery :
$(window).on('load resize', function(){ var win = $(window), bl1 = $('#block_1'), bl2 = $('#block_2'), h1 = bl1.height(), h2 = bl2.height(); if(win.width() < 520){ bl2.css({ 'transform' :'translateY(- ' + h1 + 'px)', '-webkit-transform' :'translateY(' + -h1 + 'px)' }); bl1.css({ 'transform' :'translateY(' + h2 + 'px)', '-webkit-transform' :'translateY(' + h2 + 'px)' }); } else { bl2.css({ 'transform' :'translateY(0px)', '-webkit-transform' :'translateY(0px)' }); bl1.css({ 'transform' :'translateY(0px)', '-webkit-transform' :'translateY(0px)' }); } });
#block_1 { height:50px; background:red; } #block_2 { height:35px; background:green; }
<script src="https://code.jquery.com/jquery-2.1.4.js"></script> <div class="row"> <div id="block_1">Блок 1</div> <div id="block_2">Блок 2</div> </div>