Class 3
Welcome! Please fill out the pizza poll at http://tinyurl.com/gdipizzaparty
The Viewport Dimensions extension displays the viewport dimensions in the lower right corner of the browser window when it's resized. This is helpful for responsive coding.
Awesome! 👍
You should now have four identical files with different names: index.html, africa.html, diet.html, and stripes.html
CSS for columns with margins, which is used to align content (Example »)
Grid systems use relative units (e.g. % and vw) instead of fixed units (e.g. px) so that the layout adjusts according to the viewport width
At narrower breakpoints (e.g. tablet or mobile), each column expands to fill the viewport in a single column
Most frameworks are on 12 columns or 16 columns, and include styling for common elements such as headings, buttons, and tables
max-width
on each row.Our grid CSS was generated with a grid generator, but the unneccessary CSS has been removed. Today we'll be focusing on using the grid system in the HTML.
Use the row class on each row of content:
<section class="row">
</section>
Within the row, use the column class and the width class (e.g. span_4_of_12) on each column of content:
<section class="row">
<div class="column span_4_of_12">
I'm the first of three columns!
</div>
<div class="column span_4_of_12">
I'm the second of three columns!
</div>
<div class="column span_4_of_12">
I'm the third of three columns!
</div>
</section>
Tip: To use multiple classes on a single element, separate each class with a space in your HTML as shown above.
Let's put our grid system to use in the HTML!
To make images fit to their containers, some extra properties are required:
img {
max-width: 100%;
box-sizing: border-box;
}
Together these two properties force images to stay within their containers
See the Pen Responsive Images - Before by Liz Shaw (@anythingcodes) on CodePen.
You can now make gradients with CSS3 — no image-editing required!
Use background-image
with linear-gradient
:
selector {
background-image: linear-gradient(red, white);
}
The first is the top color, while the second is the bottom color
See the Pen Linear Gradients - Two Values by Liz Shaw (@anythingcodes) on CodePen.
Bonus Functionality
You can use as many values as you want, and specify where the gradient should begin:
See the Pen Linear Gradients by Liz Shaw (@anythingcodes) on CodePen.
You can even make radial gradients
To save yourself some time, bookmark the Ultimate CSS Gradient Generator
Let's add a linear gradient to our Mission link!
Feel free to use the Ultimate CSS Gradient Generator
Visit your page and narrow the browser window
The columns you set up are fluid and responsive, since they respond to the viewport width, but don't collapse into a single column
How do we make that happen? With media queries
Within each media query rule, put CSS rules you would like to override for that breakpoint
@media screen and (max-width: 600px) {
.column {
margin: 1% 0;
width: 100%;
}
.some-other-class {
background-color: yellow;
}
}
Always use media queries at the end of your CSS file
Tip: Remember to watch your closing brackets!
See the Pen Media Queries - Columns by Liz Shaw (@anythingcodes) on CodePen.
See the Pen Media Queries by Liz Shaw (@anythingcodes) on CodePen.
The temptation is to add breakpoints based on whatever device is popular at the time (e.g. 768px)
This is a bad idea
After all, responsive design is about any and every potential screen size!
The Golden Rule: Keep it fluid
Add a breakpoint where your design breaks
Let's add a mobile breakpoint to make the columns take up the entire viewport!
Before you leave, remember to fill out the pizza poll!
http://tinyurl.com/gdipizzaparty