<section>
  <div class="grid__container">
  </div>
</section>

<div class="form">
  <div class="controle">
    <div class="button" id="add">
      <svg t="1621567639573" class="button__icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8088" width="200" height="200">
        <path d="M696 480H544V328c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v152H328c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8h152v152c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V544h152c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8z" p-id="8089"></path>
        <path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64z m0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z" p-id="8090"></path>
      </svg>
    </div>
    <div class="button" id="subtract">
      <svg t="1621567672920" class="button__icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8222" width="200" height="200">
        <path d="M696 480H328c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8h368c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8z" p-id="8223"></path>
        <path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64z m0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z" p-id="8224"></path>
      </svg>
    </div>
  </div>
  <div class="controle">
    <span>display:</span>
    <label for="block">
      <input type="radio" name="display" id="block" value="block" checked />
      block
    </label>
    <label for="grid">
      <input type="radio" name="display" id="grid" value="grid" />
      grid
    </label>
    <label for="inline-grid">
      <input type="radio" name="display" id="inline-grid" value="inline-grid" />
      inline-grid
    </label>
  </div>
</div>
@import url("https://fonts.googleapis.com/css2?family=Exo:wght@600&display=swap");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  width: 100vw;
  min-height: 100vh;

  display: flex;
  justify-content: center;
  flex-direction: column;
  gap: 20px;
  font-family: "Exo", Arial, sans-serif;
  background-color: #f7f7f7;

  padding: 20px;
}

section {
  margin: 0 auto;

  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  box-shadow: 0 0 0 6px rgb(0 0 0 / 13%);
  border-radius: 3px;
  gap: 20px;
}

.grid__container {
  box-shadow: 0 0 0 1px #f36;
  position: relative;
  /*   min-width: 20vmin; */
  /*   min-height: 20vmin; */
}

.grid__item {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f7f7f7;
  position: relative;
  counter-increment: item;
  min-width: 10vmin;
  aspect-ratio: 1 / 1;
}

.grid__item::before {
  content: "i" counter(item);
  color: #fff;
  font-size: 1.2rem;
  text-shadow: 1px 1px 0 rgba(0 0 0 / 0.25);
  position: absolute;
  z-index: 2;
  background-color: rgb(0 0 0 / 0.6);
  background-image: conic-gradient(
    from 90deg at 40% -25%,
    #ffd700,
    #f79d03,
    #ee6907,
    #e6390a,
    #de0d0d,
    #d61039,
    #cf1261,
    #c71585,
    #cf1261,
    #d61039,
    #de0d0d,
    #ee6907,
    #f79d03,
    #ffd700,
    #ffd700,
    #ffd700
  );
  width: 32px;
  aspect-ratio: 1 / 1;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  filter: drop-shadow(0 0 3px rgb(255 255 255 / 0.5));
}

.grid__item:nth-child(1) {
  background-color: #f1c2c6;
}

.grid__item:nth-child(2) {
  background-color: #dac2f1;
}

.grid__item:nth-child(3) {
  background-color: #ccf1c2;
}

.grid__item:nth-child(4) {
  background-color: #c2e9f1;
}

.grid__item:nth-child(5) {
  background-color: #f1ebc2;
}
.grid__item:nth-child(6) {
  background-color: #09f;
}

.grid__item:nth-child(7) {
  background-color: #ff5722;
}

.grid__item:nth-child(8) {
  background-color: #8bc34a;
}

.grid__item:nth-child(9) {
  background-color: #f66803;
}

.grid__item:nth-child(10) {
  background-color: #0d815f;
}
.grid__item:nth-child(11) {
  background-color: #28d1c2;
}
.grid__item:nth-child(12) {
  background-color: #4a28d1;
}
h3 {
  margin: 20px auto;
}

.form {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  gap: 15px;
}

.button {
  --background: #275efe;
  --rectangle: #184fee;
  --success: #4672f1;
  --text: #fff;
  --arrow: #fff;
  --checkmark: #fff;
  --shadow: rgba(10, 22, 50, 0.24);
  display: flex;
  background: var(--background);
  border-radius: 50%;
  box-shadow: 0 2px 8px -1px var(--shadow);
  color: var(--text);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  border: none 0;
  width: 44px;
  aspect-ratio: 1 / 1;
  cursor: pointer;
}

#subtract {
  --background: #242836;
  --rectangle: #1c212e;
  --arrow: #f5f9ff;
  --text: #f5f9ff;
  --success: #2f3545;
}

.button:hover {
  transform: scale(0.95);
  box-shadow: 0 1px 4px -1px var(--shadow);
}

.button .button__icon {
  fill: var(--text);
  width: 100%;
  height: auto;
}

.controle {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.grid__container {
  --display: block;
  display: var(--display);
}
const gridContainer = document.querySelector(".grid__container");
const addItemHander = document.getElementById("add");
const subtractItemHander = document.getElementById("subtract");
const inputs = document.querySelectorAll("input[type='radio']");

function getRandomIntInclusive(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

function getItemLength() {
  var gridItems = document.querySelectorAll(".grid__item");
  var len = gridItems.length;
  return len;
}

addItemHander.addEventListener("click", () => {
  let newItem = document.createElement("div");

  newItem.classList.add("grid__item");
  // const svgElement = `<svg class="icon"><use xlink:href="#unicorn-${getRandomIntInclusive(
  //   1,
  //   9
  // )}"></use></svg>`;
  // newItem.innerHTML = svgElement;
  gridContainer.appendChild(newItem);

  getItemLength();
});

subtractItemHander.addEventListener("click", () => {
  const items = getItemLength();
  if (items > 0) {
    gridContainer.removeChild(gridContainer.children[items - 1]);
  }
});

inputs.forEach((input, index) => {
  input.addEventListener("click", (etv) => {
    gridContainer.style.setProperty("--display", etv.target.value);
  });
});
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.