The align-content
only has effect in conjunction with the property flex-wrap
with the value wrap
and if there is line break.
For example, if you have a container of 100px
flex with two daughter Ivs that do not fit in width, there will be a mandatory line break. Soon, the align-content
will define the position of the daughters.
Example of two daughters, one with 80px
and another with 30px
. Soon, 80px + 30px = 120px, is larger than the container width, and this will force the line break with flex-wrap: wrap
, and the align-content
will define the alignment of the Divs. In the example below, in the center of the container:
.it{
display: flex;
align-content: center;
width: 100px;
height: 200px;
background: red;
flex-wrap: wrap;
}
.it div{
background: blue;
}
#f1{
width: 80px;
height: 30px;
}
#f2{
width: 30px;
height: 30px;
}
<div class="it">
<div id="f1">div1</div>
<div id="f2">div2</div>
</div>
If there is no line break, that is, if the two daughter Ivs are equal to or less than the container width, there will be no line break, so the property align-content
will have no effect:
.it{
display: flex;
align-content: flex-end;
width: 100px;
height: 200px;
background: red;
flex-wrap: wrap;
}
.it div {
background: blue;
}
#f1{
width: 80px;
height: 30px;
}
#f2{
width: 20px;
height: 30px;
}
<div class="it">
<div id="f1">div1</div>
<div id="f2">div2</div>
</div>
Already the property align-items
will align all daughter Divs independent of line break or not. If there is line break, it will align Divs equally in the container:
.it{
display: flex;
align-items: flex-start;
width: 100px;
height: 200px;
background: red;
flex-wrap: wrap;
}
.it div {
background: blue;
}
#f1{
width: 80px;
height: 30px;
}
#f2{
width: 30px;
height: 30px;
}
<div class="it">
<div id="f1">div1</div>
<div id="f2">div2</div>
</div>
If there is no line break, in the same way:
.it{
display: flex;
align-items: center;
width: 100px;
height: 200px;
background: red;
}
.it div {
background: blue;
}
#f1{
width: 80px;
height: 30px;
}
#f2{
width: 20px;
height: 30px;
}
<div class="it">
<div id="f1">div1</div>
<div id="f2">div2</div>
</div>
Good explanation, Uncle, just a BS. is that to work the parent flex container needs tb to have a set height, without a height on the parent it will always have the height of the children, and alignments will not be applied pq has no height "left" to align them inside the parent container...
– hugocsl
Exactly uncle. Man, to tell you the truth, there’s a lot to explain in these properties... I tried to be as short as possible anyway :D
– Sam
But the other answer was good tb, very synthetic, but good.
– Sam