<div class="flex-container"> <div class="flex-item">flex item 1</div> <div class="flex-item">flex item 2</div> </div> <button id="row" class="btn btn-default">row</button> <button id="row-reverse" class="btn btn-default">row-reverse</button> <button id="column" class="btn btn-default">column</button> <button id="column-reverse" class="btn btn-default">column-reverse</button>
var container = $(".flex-container"); $(document).on('click','button',function(){ var id = $(this).attr('id'); container.css('flex-direction',id); });
.flex-container { display: -webkit-flex; display: flex; flex-direction: row; width: 300px; height: 240px; background-color: Silver; } .flex-item { background-color: DeepSkyBlue; width: 100px; height: 100px; margin: 5px; }