Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
  <div class="color-block">
    <div class="color-input"></div>
    <button type="button" class="color-btn red"></button>
    <button type="button" class="color-btn green"></button>
    <button type="button" class="color-btn blue"></button>
    <button type="button" class="color-btn yellow"></button>
  </div>

<div class="sneakers-block">
    <div class="text-input"></div>
    <ul class="sneakers-buttons">
      <li>Air Max Plus</li>
      <li>Air Force 1 Crater FlyKnit</li>
      <li>LeBron 18 Low</li>
      <li>Mercurial Vapor 14 Elite AG</li>
      <li>Очистить поле</li>
    </ul>
  </div>

<div class="counter-block">
    <button type="button" data-type="minus">
      <div class="minus-icon"></div>
    </button>
    <div class="counter-display">1</div>
    <button type="button" data-type="plus">
      <div class="plus-icon"></div>
      <div class="plus-icon"></div>
    </button>
  </div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}
body {
  background-color: #000000;
  font-family: sans-serif;
  font-size: 18px;
  line-height: 22px;
  margin:0 auto;
  color: #ffffff;
}
.container {
  margin:0 auto;
  max-width: 800px;

}

.color-block {
  display: grid;
  grid-template-columns: repeat(4, 85px);
  grid-template-rows: 85px 85px;
  grid-gap: 30px 20px;
  max-width: 400px;
  padding-top: 50px;
}

.color-input {
  background-color: #f6f8f9;
  grid-column: 1/-1;
  border-radius: 20px;
}

.color-btn {
  grid-column: span 1;
  border-radius: 100px;
  border: none;
  width: 100%;
  height: 100%;
  padding: 0;
  cursor: pointer;
}
.color-btn:hover {
  transform: scale(1.1);
  transition: 0.4s ease;
}

.red {
  background-color: #ff0000;
}

.green {
  background-color: #008000;
}

.blue {
  background-color: #0000ff;
}

.yellow {
  background-color: #ffff00;
}

.sneakers-block {
  margin-top: 100px;
}
.text-input {
  background-color: #f6f8f9;
  width: 400px;
  padding: 15px 30px 15px 30px;
  border-radius: 20px;
  margin-bottom: 20px;
  min-height: 57px;
  line-height: 27px;
  max-height: 100px;
  overflow-y: scroll;
  color: #000000;
}

ul {
  list-style-type: none;
  padding: 0;
  margin: 0;
}

li {
  display: inline-block;
  border: 1px solid #ffffff;
  border-radius: 100px;
  text-align: center;
  padding: 10px 30px;
  margin-right: 5px;
  margin-bottom: 10px;
  cursor: pointer;
}

li:last-child {
  color: #ff0000;
  border: 1px solid #ff0000;
}

.counter-block {
  margin-top: 80px;
  width: 200px;
  height: 50px;
  background-color: #f6f8f9;
  border-radius: 15px;
  display: flex;
  justify-content: space-between;
  overflow: hidden;
  color: #000000;
}

.counter-block button {
  width: 50px;
  height: 100%;
  border: none;
  background-color: #18a0fb;
}

.counter-block button:hover {
  opacity: 70%;
  cursor: pointer;
}

.minus-icon,
.plus-icon {
  width: 18px;
  height: 2px;
  background-color: #fff;
  margin: 0 auto;
}

.plus-icon:first-child {
  transform: rotate(90deg) translateX(2px);
}

.counter-display {
  font-size: 26px;
  line-height: 50px;
}
              
            
!

JS

              
                document.addEventListener("DOMContentLoaded", function (event) {
  // найти кнопки
  let colorButton = document.querySelectorAll(".color-btn");
  // проверить, что есть хотя бы 1
  if (colorButton.lenght != 0) {
    // по клику на кнопку брать класс кнопки и вставляем в инпут
    colorButton.forEach(function (item) {
      item.addEventListener("click", function (event) {
        let currentBg = item.classList[1];
        let colorInput = document.querySelector(".color-input");
        let colorInputBg = colorInput.classList[1];
        colorInput.classList.remove(colorInputBg);
        colorInput.classList.add(currentBg);
      });
    });
  }

  //находим все li
  let listItems = document.querySelectorAll(".sneakers-buttons > li");
  // проверяем, что есть хотя бы 1
  if (listItems.lenght != 0) {
    // вешаем событие клик по очереди на каждую кнопку
    let textInput = document.querySelector(".text-input");
    listItems.forEach(function (item) {
      item.addEventListener("click", function (event) {
        // по клику берем контент из li и добавляем его в инпут
        let text = item.textContent;

        textInput.textContent = textInput.textContent + " " + text;
      });
    });
    let clear = document.querySelector("li:last-child");
    if (clear) {
      clear.addEventListener("click", function (event) {
        textInput.textContent = "";
      });
    }
  }

  //counter
  let counterButton = document.querySelectorAll(".counter-block button");

  if (counterButton.lenght != 0) {
    counterButton.forEach(function (item) {
      let counterDisplay = document.querySelector(".counter-display");

      if (item.dataset.type == "minus") {
        item.addEventListener("click", function (event) {
          let result = parseInt(counterDisplay.textContent) - 1;
          if (result >= 0) {
            counterDisplay.textContent = result;
          }
        });
      }

      if (item.dataset.type == "plus") {
        item.addEventListener("click", function (event) {
          counterDisplay.textContent = parseInt(counterDisplay.textContent) + 1;
        });
      }
    });
  }

  //size block
  let sizeButtons = document.querySelectorAll(".size-block button");
  if (sizeButtons != 0) {
    sizeButtons.forEach(function (item) {
      item.addEventListener("click", function (event) {
        let target = document.querySelector(".target");
        // let targetWidth = target.style.width;
        // let targetHeight = target.style.height;
        let step = 20;

        if (item.dataset.type == "less") {
          if (parseInt(target.style.width) >= 50) {
            target.style.width = parseInt(target.style.width) - step + "px";
            target.style.height = parseInt(target.style.height) - step + "px";
          }
        }

        if (item.dataset.type == "more") {
          if (parseInt(target.style.width) <= 500) {
            target.style.width = parseInt(target.style.width) + step + "px";
            target.style.height = parseInt(target.style.height) + step + "px";
          };
        };
      });
    });
  };
});

              
            
!
999px

Console