02-CSS Grid and Responsive Web Design Exercises
02-CSS Grid and Responsive Web Design Exercises
Responsive design
Understanding
My mantra: however, I encourage you to read around and find your own way of doing things as
well. There's no common consensus on this btw.
**note: This rule changes if you are designing a desktop first application. Applications are generally
designed desktop first and many times their mobile counterparts come later or there are just mobile
apps and no mobile support. If you’re working in a team, follow what they’re doing.
We do mobile first, we define a media query for tablet but don’t populate it now. And then we define
everything for the desktop.
/* Default styles for mobile devices */
body {
font-size: 14px;
}
Challenge
**note: We are using 600px so that it is easier for me to teach. You can change the breakpoints to
1024 when publishing the website, or 768 if you want tablet to have desktop layouts.
Understanding
1. By following the rule of cascade your second rule overrides the first. But it overrides only at
specific screen intervals.
2. Now your mobile look will have a yellow background while your desktop look will have
a transparent background.
3. This is mobile first design. You can even take the first rule and put it in mobile.layout.css and
the other rule in desktop.layout.css and apply both CSS one after another. Just make sure that
everything in desktop.layout.css file is in a media query.
Solution
https://codesandbox.io/s/first-media-query-solution-iogf29
Understanding
1. It’s important to change the font size when the screen size varies. Especially the headings
should feel right on a desktop.
You don’t need to be a designer to make good UI, you just need to be ready with a good set of
defaults and follow a theme. -Tanay Pratap
Challenge
Create a simple webpage with responsive typography that adapts to different screen sizes. Your
webpage should include a title, subtitle, and a paragraph. The font size of the text elements should
change based on the screen size.
Units
Solution
https://codesandbox.io/s/responsive-typography-x3medr
Grids
Grids are much like flex.
Grids are useful more for layout in 2D while flex are in 1D. So, reach out to grids when you are
laying out the floor plan for your app.
Syntax
display: grid; /* step I*/
grid-template-columns: 200px 1fr auto;
grid-column-gap: 16px;
/* to do rows */
grid-template-rows: 1fr 1fr 1fr;
grid-row-gap: 0.5rem;
COPY
Challenge
https://codesandbox.io/s/grid-column-rows-9gg66u
Challenge
https://codesandbox.io/s/responsive-grids-otl85j
Challenge
Reset the whole class layout from the ex01 into three views as shown below
https://codesandbox.io/s/mobile-friendly-grid-dpnxmv
Understanding
https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-areas
Syntax
.nav {
grid-area: nav;
}
.main {
grid-area: row;
}
.aside-main {
grid-area: aside;
}
.footer {
grid-area: footer;
}
.layout {
grid-template-areas:
'nav nav nav'
'row row aside'
'row row aside'
'footer footer footer';
}
COPY
Homework
Using the template-area layout a docsite as shown below. You can work out the details later.
Solution #
https://codesandbox.io/s/responsive-grids-mobile-view-forked-y1p1q1