cfarm.co/rwd2
Q: For fluid grids, container widths should use ___? instead of pixels
A: Percentages
Q: What is the formula to calculate your width percentage?
A: Target รท context = result
Q: The Viewport <meta> tag changes the _____? of your HTML document:
A: C. Scale
Using percentage widths & flexible images, add some cat photos to your page to match our design:
For many responsive styles, you want to impose a maximum width on your elements that have percentage values:
.gifs img {
width: 33%;
max-width: 85px;
}
.gifs img {
width: 33%;
max-width: 85px;
}
.container {
width: 100%;
max-width: 960px;
}
Sometimes our fluid grids are too small to fit our content nicely in our design at small screen sizes:
Media Queries apply CSS based on conditions that you decide (usually width, but can also be resolution, device size, height, media type).
@media print {
* {
background: white !important;
}
}
@media only screen and (min-width:600px) {
header {
/* styles for only 600px wide & up */
}
}
Just like with a print stylesheet, you can add media queries based on screen size to any element you want:
Most important elements to target with media queries are usually layout-related, like your fluid grid styles.
.container {
margin: 0 auto;
width: 100%;
}
@media only screen and (min-width:960px) {
.container {
width: 960px;
}
}
Fix your squished grid callout styles:
@media only screen and (min-width:960px) {
.callout {
margin: 0 ??% 0 0;
width: ???%;
float: left;
}
}
Here's how our callout divs should look now, without floats or widths on the left, and with floats and widths on the right:
Media queries can also use:
Convert pixel values to ems with pxtoem.com
@media only screen and (min-width:60em) {
.container {
width: 100%;
max-width: 960px;
}
}
Use multiple parameters to target in-between sizes (aka breakpoints)
@media only screen and (min-width:700px) and (max-width: 800px) {
.nav {
font-size: 110%;
}
}
Make a mobile-first responsive site:
The points in your layout where you add a media query, or where things shift and change.
/* this is a 60em or 960px wide breakpoint */
@media only screen and (min-width:60em) {
.container {
width: 100%;
max-width: 960px;
}
}
These can be based on popular device sizes, like iPhone, iPad and desktop resolutions:
.container { width: 100%; }
@media only screen and (min-width:320px) {
.container {
margin: 0 auto;
width: 320px;
}
}
@media only screen and (min-width: 768px) {
.container {
width: 768px;
}
}
@media only screen and (min-width: 960px) {
.container {
width: 960px;
}
}
Example: Eataly
Breakpoints can also be more fluid, and added only where the layout starts to look funky:
.hero-image { width: 100%; }
@media only screen and (min-width:530px) {
.container {
float: left;
width: 41.6666666666667%; /* 400px/960px */;
}
}
Example: BohConf