Grid and Flexbox Fundamentals
Guiding Principles For Responsive Design
- CSS Grid Based Layout should be the starting point. Sometimes flexbox.
- Use images that resize. Use the
picture
element. - Use CSS media queries to target specific screen sizes.
Just remember, that CSS grids were made for the web to work correctly.
Introduction to Grid
What is Grid best for?
- A series of boxes that are of the same width.
- Layouts that span across rows and or columns.
- Siblings that need to cover each other.
Games to learn:
- https://cssgridgarden.com/
- https://codingfantasy.com/games/css-grid-attack
- https://gridcritters.com/
Responsive Web Design
There are two approaches to responsive web design:
- Mobile First: Build your mobile styles outside the media queries and use min-width media queries.
- Desktop First: Build your desktop styles inside the media queries and use max-width media queries.
Mobile First is a better approach but it depends on the project.
CodePens for each section
- Introduction to Grid
- Introduction to Grid 2
- Grid Span and Repeat
- Grid Area
- Media Queries with Grid Layout: Desktop First
- Media Queries with Grid Layout: Mobile First
- Overlapping Grid Cells
- Overlapping Grid Cells Art
Understanding Grid Concepts
- If your gaps are bigger than expected in a Grid, think that the element inside a cell has a margin.
minmax()
is a function that returns the minimum and maximum values.auto-fit
andauto-fill
are keywords that are used with thegrid-template-columns
andgrid-template-rows
properties. This can help grid behave like flexbox.- 1fr is defined by the tallest section if the height or width is auto.
Where to Use Flexbox?
- A series of boxes that are not the same size.
- A series of boxes that are not in an event sized.
- Flexbox was not designed to be locked down for layouts.