0

введите сюда описание изображенияНе знаю как сделать кнопку при которой можно было бы сменить вид объектов как на скриншоте, html/css/js

1
  • на кнопки вещайте обработчик и в зависимости от обработчика вешаете класс, а этим классом управляете грид системой
    – meine
    28 фев 2020 в 10:10

1 ответ 1

1

Как вариант:

const el1 = document.getElementById("rows");
const el2 = document.getElementById("columns");
const mainLayaout = document.getElementById("mainLayaout");
el1.addEventListener("click", toRows, false);
el2.addEventListener("click", toColumns, false);

function toRows() {
  mainLayaout.style.cssText = "display: flex; flex-direction: column"; 
}

function toColumns() {
  mainLayaout.style.cssText = "display: grid; grid-template-columns: repeat(3, 1fr)"; 
}
#card {
  width: 100px;
  height: 100px;
  background: red;
  margin: 1em;
}
<button id="rows">Список</button>
<button id="columns">Колонки</button>
<div id="mainLayaout">
  <section id="card"></section>
  <section id="card"></section>
  <section id="card"></section>
</div>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.