<header>
<h2 class="title">alignItems</h2>
<p class="description">Вирівнює flex-елементи вздовж перпендикулярної до головної осі лінії всередині контейнера.</p>
</header>
<main>
<div class="controls">
<label>
<input type="radio" name="alignment" value="flex-start" checked> flex-start
</label>
<label>
<input type="radio" name="alignment" value="flex-end"> flex-end
</label>
<label>
<input type="radio" name="alignment" value="center"> center
</label>
<label>
<input type="radio" name="alignment" value="baseline"> baseline
</label>
<label>
<input type="radio" name="alignment" value="stretch"> stretch
</label>
</div>
<div class="result">
<div class="flex-container">
<div class="item tall">Елемент 1<br>з додатковим<br>текстом</div>
<div class="item">Елемент 2</div>
<div class="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;
height: 200px;
align-items: flex-start;
}
.item {
background-color: #ccc;
border: 1px solid #999;
padding: 10px;
margin: 5px;
}
.tall {
font-size: 1.2em;
}
const alignments = document.querySelectorAll('input[name="alignment"]');
const container = document.querySelector('.flex-container');
alignments.forEach(alignment => {
alignment.addEventListener('change', () => {
container.style.alignItems = alignment.value;
});
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.