I am trying to learn Flexbox and I am having a problem with this exercise. The task is to have a div with 2 to 4 div's inside of it. When there are 2 or 3 div's they should be divided equal width and all should be the height of the main div. But when there are 4 div elements inside the main div, then they would be in two rows which contain two div's each.
How can I make this possible? I have tried some on my own but I couldn't get it to work:
<div id="wrapper">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
This is the CSS I have created:
#wrapper{
width: 100%;
height: 100%;
display: flex;
flex-wrap: wrap;
}
.item{
min-width: 33%;
}
Picture of how it should look with 2 elements inside the wrapper Div
Picture of how it should look with 3 elements inside the wrapper Div
Picture of how it should look with 4 elements inside the wrapper Div