I am doing some exercises to learn how flexbox works, and there is something that is bugging me and I would like to know how this works. For some reason, when I apply display:flex;
to my container, when I reduce the screen size the elements go out of the div as you can see in this picture.
This one here is the mobile view, look how the border dissapears:
.box {
color: white;
font-size: 60px;
text-align: center;
text-shadow: 4px 4px 0 rgba(0, 0, 0, .1);
}
.box1 {
background-color: rgb(0, 118, 57);
}
.box2 {
background-color: blueviolet;
}
.box3 {
background-color: chartreuse;
}
.box4 {
background-color: darkgoldenrod;
}
.box5 {
background-color: darkolivegreen;
}
.box6 {
background-color: dodgerblue;
}
.box7 {
background-color: greenyellow;
}
.box8 {
background-color: mediumseagreen;
}
.box9 {
background-color: orange;
}
.box10 {
background-color: steelblue;
}
.container {
display: flex;
border: 7px solid black;
margin: 22px 10px;
width: 80%;
}
.box {
flex: 1;
width: 50%;
padding: 20px;
/* flex-flow: row wrap; */
/* margin: 22px; */
}
<body>
<div class="container">
<div class="box box1">one </div>
<div class="box box2">two </div>
<div class="box box3">three </div>
<div class="box box4">four </div>
<div class="box box5">five </div>
<div class="box box6">six </div>
<!-- <div class="box box7">7</div> -->
<!-- <div class="box box8">8</div> -->
<!-- <div class="box box9">9</div> -->
<!-- <div class="box box10">10</div> -->
</div>
</body>
How Can I prevent this from happening? I have tried using percentage width and also properties as flex shrink, but there are no changes.