<header>
<h2 class="title">element.style.flexGrow</h2>
<p class="description">Визначає, наскільки елемент повинен розширюватися, щоб заповнити доступний простір в контейнері flex.</p>
</header>
<main>
<div class="result">
<!-- Кнопки для зміни значення flex-grow для елементів -->
<div>
<button id="growFirst">Grow First Box</button>
<button id="growSecond">Grow Second Box</button>
<button id="resetGrow">Reset Growth</button>
</div>
<!-- Flex-контейнер з елементами для демонстрації -->
<div class="flex-container">
<div id="box1" class="flex-box">Box 1</div>
<div id="box2" class="flex-box">Box 2</div>
<div id="box3" class="flex-box">Box 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;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
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;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
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%;
}
.flex-box {
flex-grow: 1;
padding: 20px;
background-color: #4CAF50;
color: white;
text-align: center;
transition: flex-grow 0.3s ease;
}
document.addEventListener('DOMContentLoaded', function() {
const box1 = document.getElementById('box1');
const box2 = document.getElementById('box2');
const box3 = document.getElementById('box3');
const growFirstButton = document.getElementById('growFirst');
const growSecondButton = document.getElementById('growSecond');
const resetGrowButton = document.getElementById('resetGrow');
growFirstButton.addEventListener('click', function() {
box1.style.flexGrow = '3';
box2.style.flexGrow = '1';
box3.style.flexGrow = '1';
});
growSecondButton.addEventListener('click', function() {
box1.style.flexGrow = '1';
box2.style.flexGrow = '3';
box3.style.flexGrow = '1';
});
resetGrowButton.addEventListener('click', function() {
box1.style.flexGrow = '1';
box2.style.flexGrow = '1';
box3.style.flexGrow = '1';
});
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.