<header>
<h2 class="title">element.style.justifyContent</h2>
<p class="description">Керує розташуванням елементів всередині flex-контейнера вздовж головної осі.</p>
</header>
<main>
<div class="result">
<!-- Кнопки для зміни значення justifyContent -->
<div>
<button id="justifyStart">Justify Start</button>
<button id="justifyCenter">Justify Center</button>
<button id="justifyEnd">Justify End</button>
<button id="justifySpaceBetween">Space Between</button>
<button id="justifySpaceAround">Space Around</button>
<button id="justifySpaceEvenly">Space Evenly</button>
</div>
<!-- Flex-контейнер з елементами для демонстрації -->
<div id="flexContainer" class="flex-container">
<div class="flex-item">Item 1</div>
<div class="flex-item">Item 2</div>
<div 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;
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%;
padding: 20px;
background-color: #e0e0e0;
border: 1px solid #ccc;
justify-content: flex-start; /* Початкове значення */
}
.flex-item {
padding: 20px;
background-color: #4CAF50;
color: white;
text-align: center;
}
document.addEventListener('DOMContentLoaded', function() {
const flexContainer = document.getElementById('flexContainer');
const justifyStartButton = document.getElementById('justifyStart');
const justifyCenterButton = document.getElementById('justifyCenter');
const justifyEndButton = document.getElementById('justifyEnd');
const justifySpaceBetweenButton = document.getElementById('justifySpaceBetween');
const justifySpaceAroundButton = document.getElementById('justifySpaceAround');
const justifySpaceEvenlyButton = document.getElementById('justifySpaceEvenly');
justifyStartButton.addEventListener('click', function() {
flexContainer.style.justifyContent = 'flex-start';
});
justifyCenterButton.addEventListener('click', function() {
flexContainer.style.justifyContent = 'center';
});
justifyEndButton.addEventListener('click', function() {
flexContainer.style.justifyContent = 'flex-end';
});
justifySpaceBetweenButton.addEventListener('click', function() {
flexContainer.style.justifyContent = 'space-between';
});
justifySpaceAroundButton.addEventListener('click', function() {
flexContainer.style.justifyContent = 'space-around';
});
justifySpaceEvenlyButton.addEventListener('click', function() {
flexContainer.style.justifyContent = 'space-evenly';
});
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.