<div class="wrapper">
<button data-view="horizontal">Горизонтально</button>
<button data-view="vertical">Вертикально</button>
<div class="card-wrapper active" data-view="horizontal">
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
</div>
<div class="card-wrapper" data-view="vertical">
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
</div>
</div>
.card-wrapper {
display: none;
}
.card-wrapper.active {
display: flex;
}
.card-wrapper[data-view="horizontal"] {
flex-direction: row;
}
.card-wrapper[data-view="vertical"] {
flex-direction: column;
}
document.querySelector('.wrapper').addEventListener('click', function(e) {
const view = e.target.dataset.view;
if (view && e.target.tagName === 'BUTTON') {
document.querySelectorAll('.card-wrapper').forEach(n => {
n.classList.toggle('active', n.dataset.view === view);
});
}
});
https://jsfiddle.net/dq2hpfzj/