4 ms·
The general thinking is * use CSS Grid for layout in 2 dimensions. Page level layout essentially * use Flexbox for layout in 1 dimension. "module" level layou
by ahoy 10y ago
The general thinking is
* 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.
- gsnedders 10y agoEssentially, with what I've done with Grid, my opinion is Flexbox makes the 1D case simpler than the equivalent thing with Grid. AFAICT, this is the prevailing view the reason for the above.
- konschubert 10y agoI am really confused with CSS grid. How does it adjust to smaller screen sizes? My impression is that it is rigid like an html table, and we have mostly abandoned these for good reasons. 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.
- WorldMaker 10y agoMost of the same tricks to flexbox reordering and reflowing for responsive layouts apply to CSS grid as well. You can use @media queries to switch grid layouts based on things like screen size. With more recent specs you get a further advantage in that where flexbox reordering is based on easy to mix up numbering (at this media layout this Div A is 1, Div B is 2, Div C is 3, but in this other layout Div A is 3, Div B is 1 and Div C is 2) for naming your grid sections (Div A is "sidebar" and Div B is "main-content" and Div C is "footer"); the names stay consistent and only your designation of which name goes where in the grid flow (which is managed at the parent container level) shifts with media query reflows.
- WorldMaker 10y agoFor what it is worth, I built a complicated 2D, responsive layout for my blog (mostly to amuse myself). I allowed myself whatever tech choices I felt comfortable using and I wish I could have used Grid but browser support wasn't where I would have liked and neither was prollyfill support. The Flexbox version I built is a lot less simple to follow in the CSS media query switching than the Grid equivalent would have been (but Flexbox version has been quite reliable across browsers). Though the biggest loss in not having Grid support turned out to be what I wanted to do for DL (DD, DT) layout, since I tend to use those quite heavily, and neither Flexbox nor CSS Table Layout suffice (due to DT+DD[+DD...] sets lacking a wrapper element, per HTML spec).
- konschubert 10y agoI just feel like using media queries isn't really responsive. 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.