<main>
<h2>Handling Extra Space Between Flex Lines: <br><code>align-content</code></h2>
<div class="btns">
<label for="stretch">stretch <input type="radio" name="alignitems" value="stretch" id="stretch" checked></label>
<label for="flex-start">flex-start <input type="radio" name="alignitems" value="flex-start" id="flex-start"></label>
<label for="flex-end">flex-end <input type="radio" name="alignitems" value="flex-end" id="flex-end"></label><br>
<label for="center">center <input type="radio" name="alignitems" value="center" id="center"></label>
<label for="space-between">space-between <input type="radio" name="alignitems" value="space-between" id="space-between"></label>
<label for="space-around">space-around <input type="radio" name="alignitems" value="space-around" id="space-around"></label>
</div>
<div class="container">
<div class="item">1</div>
<div class="item large">2</div>
<div class="item large">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
<div class="item large">8</div>
<div class="item">9</div>
<div class="item">10</div>
<div class="item">11</div>
<div class="item">12</div>
</div>
<div class="dir">
<label for="ltr">left-to-right <input type="radio" value="ltr" name="direction" id="ltr" checked></label>
<label for="rtl">right-to-left <input type="radio" value="rtl" name="direction" id="rtl"></label>
</div>
</main>
body {
font-family: Arial, sans-serif;
font-size: 1.3em;
padding: 0 2em 3em;
line-height: 1.4;
}
main {
max-width: 800px;
margin: 0 auto;
}
h2 {
margin-top: 14px;
text-align: center;
}
code {
font-family: Consolas, monospace;
background: #ccc;
padding: 1px 3px;
}
.btns {
padding-bottom: 1em;
text-align: center;
}
.dir {
text-align: center;
}
label {
margin-right: 1.3em;
padding: 8px;
}
.container {
min-height: 500px;
border: solid 2px;
margin-bottom: 1em;
background: #b2d5ff;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.ltr {
direction: ltr;
}
.rtl {
direction: rtl;
}
.auto {
align-items: auto;
}
.flex-start {
align-content: flex-start;
}
.flex-end {
align-content: flex-end;
}
.center {
align-content: center;
}
.stretch {
align-content: stretch;
}
.space-between {
align-content: space-between;
}
.space-around {
align-content: space-around;
}
.item {
min-width: 15%;
background: #007ed3;
border: solid 2px #305077;
margin: 4px;
text-align: center;
font-size: 3em;
color: white;
font-weight: bold;
line-height: 2.4;
}
.large {
height: 160px;
}
let btns = document.querySelector('.btns').querySelectorAll('input'),
dirs = document.querySelector('.dir').querySelectorAll('input'),
container = document.querySelector('.container');
for (i of btns) {
(function(i) {
i.addEventListener('click', function() {
clearClasses(container, btns);
container.classList.add(i.value);
}, false);
})(i);
}
for (i of dirs) {
(function(i) {
i.addEventListener('click', function() {
clearClasses(container, dirs);
container.classList.add(i.value);
}, false);
})(i);
}
function clearClasses (el, cl) {
for (i of cl) {
el.classList.remove(i.value);
}
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.