by apaprocki · 9y ago · 0 comments
* use CSS Grid for layout in 2 dimensions. Page level layout essentially
* use Flexbox for layout in 1 dimension. "module" level layout.
These are not hard and fast rules, like much in CSS.
With flexbox I can make the sidebar float below the content at a certain screen size. Can I do this with grid?
So if anything, it seems to me that the global layout should be done with flexbox, and the grid is for smaller, more rigid elements that do not need to re-order on different screen sizes.
It's like trying to make a list of all possible screen formats and trying to define a layout for each.
In my opinion media queries are an antipattern because they create code bloat and need frequent maintainance.
It seems unsuitable for writing responsive pages where containers float below each other if there is not enough horizontal space.
I would love to stand corrected, but my impression is that for responsive page designs, you will need flexbox, not the grid.
It might have been nice if CSS had more standard media queries that stated more explicitly what is desired (@media tablet-screen {} or something similar), but the compromise that remains is a solid one that mostly works and is adaptable/evolvable to potential future shifts in device profiles (both in browsers choosing different "effective pixel" ratings over time on the one side and CSS writers shifting breakpoints on the other).
Yes, new CSS standards like Grid/Flexbox could try to invent new wheels to deal with responsive issues, but it's easier for those standards to get adopted if they just subsume existing standards such as media queries.
I'm curious how you manage to avoid media queries while building "truly responsive" websites.