When box-container have align-items: flex-start
boxes marked as b3
and b4
do not want to wrap items they contain. Why is it?
If you remove the line, wrapping works (bonus question, why items don't stretch parent container?)
#box-container {
width: 100%;
height: 100vh;
background-color: hsl(0, 0%, 80%);
display: flex;
flex-direction: row;
align-items: flex-start;
/* !!! */
}
.box {
min-width: 135px;
min-height: 135px;
padding: 5px;
display: flex;
flex-wrap: wrap;
/* переносит на следующую строку/столбец элемент, если мало места */
align-content: flex-start;
/* выравнивание рядов по вертикали */
justify-items: flex-start;
/* выравнивание столбцов по горизонтали */
}
#b1 {
background-color: hsl(0, 25%, 50%);
flex-direction: row;
}
#b2 {
background-color: hsl(90, 25%, 50%);
flex-direction: row-reverse;
}
#b3 {
background-color: hsl(180, 25%, 50%);
flex-direction: column;
}
#b4 {
background-color: hsl(270, 25%, 50%);
flex-direction: column-reverse;
}
.smallbox {
width: 125px;
height: 125px;
margin: 5px;
display: flex;
align-items: center;
/* выравнивание содержимого по вертикали */
justify-content: center;
/* выравнивание содержимого по горизонтали */
}
<html>
<head>
<title>CSSFlexbox Main Page</title>
<link rel="stylesheet" href="style.css">
</head>
<body style="margin: 0;">
<div id="box-container">
<div id="b1" class="box">
<div class="smallbox sb1" style="background-color:hsla(0, 50%, 50%);">
<h2>1</h2>
</div>
<div class="smallbox sb2" style="background-color:hsla(30, 50%, 50%);">
<h2>2</h2>
</div>
<div class="smallbox sb3" style="background-color:hsla(60, 50%, 50%);">
<h2>3</h2>
</div>
</div>
<div id="b2" class="box">
<div class="smallbox sb1" style="background-color:hsla(90, 50%, 50%);">
<h2>1</h2>
</div>
<div class="smallbox sb2" style="background-color:hsla(120, 50%, 50%);">
<h2>2</h2>
</div>
<div class="smallbox sb3" style="background-color:hsla(150, 50%, 50%);">
<h2>3</h2>
</div>
</div>
<div id="b3" class="box">
<div class="smallbox sb1" style="background-color:hsla(180, 50%, 50%);">
<h2>1</h2>
</div>
<div class="smallbox sb2" style="background-color:hsla(210, 50%, 50%);">
<h2>2</h2>
</div>
<div class="smallbox sb3" style="background-color:hsla(240, 50%, 50%);">
<h2>3</h2>
</div>
</div>
<div id="b4" class="box">
<div class="smallbox sb1" style="background-color:hsla(270, 50%, 50%);">
<h2>1</h2>
</div>
<div class="smallbox sb2" style="background-color:hsla(300, 50%, 50%);">
<h2>2</h2>
</div>
<div class="smallbox sb3" style="background-color:hsla(330, 50%, 50%);">
<h2>3</h2>
</div>
</div>
</div>
</body>
</html>