With CSS flexbox, we can create
blocks which automatically adjust
their sizes for small and large screens.
However, most of the times,
this isn't sufficient to create
a responsive layout.
Look at the example given below.
Go to the full screen mode using
the button on the top right side of
the code editor and resize the output
panel. Notice what happens when the
width is too small:
When the screen width gets small,
the columns shrink too much,
making the text hard to read.
Also, a horizontal scrollbar appears.
This is not desired behaviour.
We need a way to change
some styles based on the screen
size. This can be done
using Media Queries.
Let's look at the same example
using media queries:
Now, resize the output panel
and
notice what happens on smaller screens.
For screen widths larger than 630px,
the blocks appear next to each other.
For screen widths smaller than 630px,
the flex-direction
gets changed to column
.
This is why, the blocks get stacked
one below the other.