I'm starting to work with flexbox, and, in order to understand flex-grow
and flex-shrink
, I used a simple program that displays two blocks and makes them take up the whole width using flex-grow: 2
in one of them and flex-grow: 1
in the other.
If I check the following line in the console: $(".one").width() === $(window).width() /3
it returns true. So far, so good.
The problem appears when I reduce the window size, because as soon as I do this the same line in the console ($(".one").width() === $(window).width() /3
) starts returning false.
I know the default value for flex-shrink
is 1
. Wouldn't that mean that the proportions between both blocks would be maintained (since they are both being shrunk by the same amount)? Can anyone explain why this result happens?
Here's my code:
* {
font-family: verdana;
margin: 0;
}
body {
background: #eee;
}
.wrapper {
width: 100%;
max-width: 2000px;
margin: 0 auto;
}
.flex-container {
display: flex;
background-color: white;
}
.box {
height: 100px;
}
.one {
background-color: red;
flex-grow: 1;
}
.two {
background-color: blue;
flex-grow: 2;
}
<div class="wrapper">
<div class="flex-container">
<div class="box one"></div>
<div class="box two"></div>
</div>
</div>