In this lesson we’ll create the Grid layout primitive component, that will allow us (together with other layout primitives) to create almost any complex layout without writing custom CSS. We’ll use Styled System to create this component.
Grid is a shortcut to create CSS Grid layouts: it’s based on the Box component but defines display: grid
. We can use it like this:
<Grid
as="footer"
gridGap={3}
justifyContent={[null, 'space-between']}
justifyItems={['center', null]}
gridAutoFlow={[null, 'column']}
>
<Box>© Chuck Norris, 1940</Box>
<Box>Have a nice day!</Box>
</Grid>
This will create two <div>
s stacked one on top of the other with a 8 pixels (third step in our spacing scale) gap on narrow screens and aligned at the left and right sides of the CSS Grid container on wide screens.
We’ll use following libraries:
You can either use this lesson’s Git repository or install them manually in your project:
npm install styled-components styled-system
Useful links and documentation:
Artem Sapegin: [0:00] Create a new markdown file, Grid.md and add some examples. In Grid.js we can copy-paste the code of the Flex component. The only thing we need to change is change display: 'flex' to display: 'grid' and change the component name to Grid.
[0:18] That's how the Grid component works. For example, we can change the gridGap property or see how responsive params are working. Now it's using a fast array item for the mobile breakpoint, but when we make the browser window wider, it's using secondary items for the [inaudible] breakpoint and the layout changes.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!