I have a container set up via flexbox. I'd like to equally distribute each of the tiles inside the container but keep them at a fixed width of 220px.
I've come close using flex-grow
and setting a min-width: 220px
, but it obviously has computationally resized the tiles in order to fill the container.
I've also set up some media queries so that the tiles stack on certain breakpoints.
With my current styling is it possible to keep these tiles at 220px without them stretching? Can this be done via flexbox? Is there an alternative that's just as good as flexbox?
.container {
border: 1px solid red;
display: flex;
flex-wrap: wrap;
margin: 0 auto;
max-width: 2000px;
}
.tiles {
border: 1px solid black;
margin: 0 15px 30px 15px;
flex-grow: 1;
padding: 0;
height: 220px;
min-width: 220px;
}
@media screen and (max-width: 1140px) {
.container {
max-width: 850px;
}
}
@media screen and (max-width: 2040px) {
.container {
max-width: 1750px;
}
}
@media screen and (max-width: 1790px) {
.container {
max-width: 1500px;
}
}
@media screen and (max-width: 1540px) {
.container {
max-width: 1250px;
}
}
@media screen and (max-width: 1290px) {
.container {
max-width: 1000px;
}
}
@media screen and (max-width: 1040px) {
.container {
max-width: 750px;
}
}
@media screen and (max-width: 790px) {
.container {
max-width: 500px;
}
}
<div class="container">
<div class="tiles"></div>
<div class="tiles"></div>
<div class="tiles"></div>
<div class="tiles"></div>
<div class="tiles"></div>
<div class="tiles"></div>
<div class="tiles"></div>
<div class="tiles"></div>
<div class="tiles"></div>
<div class="tiles"></div>
</div>