<header>
  <h2 class="title">element.style.flexShrink</h2>
  <p class="description">Керує тим, наскільки елемент має зменшуватися при обмеженому просторі в flex-контейнері.</p>
</header>
<main>
  <div class="result">
    <!-- Перемикачі для зміни значення flexShrink для елементів -->
    <div>
      <label for="shrinkItem1">Shrink Item 1</label>
      <input type="range" id="shrinkItem1" min="0" max="5" value="1">
      
      <label for="shrinkItem2">Shrink Item 2</label>
      <input type="range" id="shrinkItem2" min="0" max="5" value="1">
      
      <label for="shrinkItem3">Shrink Item 3</label>
      <input type="range" id="shrinkItem3" min="0" max="5" value="1">
    </div>
    <!-- Flex-контейнер з елементами для демонстрації -->
    <div id="flexContainer" class="flex-container">
      <div id="item1" class="flex-item">Item 1</div>
      <div id="item2" class="flex-item">Item 2</div>
      <div id="item3" class="flex-item">Item 3</div>
    </div>
  </div>
</main>
body {
  font-size: 16px;
  line-height: 1.5;
  font-family: monospace;
}

header {
  background-color: #f1f1f1;
  margin-bottom: 25px;
  padding: 15px;
  -webkit-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  -moz-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}

header h2.title {
  padding-bottom: 15px;
  border-bottom: 1px solid #999;
}

header p.description {
  font-style: italic;
  color: #222;
}

.result {
  background-color: #f8f8f8;
  padding: 15px;
  -webkit-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  -moz-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}

.flex-container {
  display: flex;
  gap: 10px;
  width: 100%;
  padding: 20px;
  background-color: #e0e0e0;
  border: 1px solid #ccc;
  overflow: hidden;
}

.flex-item {
  flex-basis: 200px;
  flex-grow: 1;
  flex-shrink: 1;
  padding: 20px;
  background-color: #4CAF50;
  color: white;
  text-align: center;
  transition: flex-shrink 0.3s ease, width 0.3s ease;
}
document.addEventListener('DOMContentLoaded', function() {
  const item1 = document.getElementById('item1');
  const item2 = document.getElementById('item2');
  const item3 = document.getElementById('item3');
  
  const shrinkItem1 = document.getElementById('shrinkItem1');
  const shrinkItem2 = document.getElementById('shrinkItem2');
  const shrinkItem3 = document.getElementById('shrinkItem3');

  shrinkItem1.addEventListener('input', function() {
    item1.style.flexShrink = this.value;
  });

  shrinkItem2.addEventListener('input', function() {
    item2.style.flexShrink = this.value;
  });

  shrinkItem3.addEventListener('input', function() {
    item3.style.flexShrink = this.value;
  });
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.