Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.
Some "rules"
Tell us about yourself.
Responsive web design is an approach to web design in which a site is crafted to provide an optimal viewing experience—easy reading and navigation with a minimum of resizing, panning, and scrolling— across a wide range of devices (from desktop computer monitors to mobile phones).-Wikipedia
As of January 2017:
.container {
width: 960px;
margin: 0 20px;
}
.content .main-column {
width: 480px;
margin-right: 20px;
}
.content .hero-image {
width: 400px;
}
.container {
width: 960px;
margin: 0 4.1667%;
}
.content .main-column {
width: 50%;
margin-right: 4.1667%;
}
.content .hero-image {
width: 41.667%;
}
.container {
width: 100%;
margin: 0 4.1667%;
}
.content .main-column {
width: 50%;
margin-right: 4.1667%;
}
Makes your page scale correctly on mobile devices.
<meta name="viewport" content="width=device-width">
Uncomment line 18 in your index.html file and compare on a mobile device to see the difference.
Like with fluid grids, percentages make images flexible in a page
img {
max-width: 100%;
}
Find the following code in your hero-image div:
<img src="http://cdn3-www.cattime.com/assets/uploads/2011/08/best-kitten-names-1.jpg"
alt="pensive kitten">
What happens when you resize the page to make it small or big?
img {
max-width: 100%;
}
What if you don’t want it to be 100% wide?
<img src="http://cdn3-www.cattime.com/assets/uploads/2011/08/best-kitten-names-1.jpg"
alt="pensive kitten"
class="small-image">
.small-image {
float: left;
width: 50%;
}
Using percentage widths & flexible images, add "Viral GIFs" photos to match our design:
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
For many responsive styles, you want to impose a maximum width on your elements that have percentage values:
.gifs img {
width: 33%;
max-width: 80px;
}
.gifs img {
width: 33%;
max-width: 80px;
}
.container {
width: 100%;
max-width: 960px;
}
.container {
width: 100%;
max-width: 960px;
}
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 (min-width:600px) {
header {
/* styles for only 600px wide & up */
}
}
Change your header element's background color so it's red at screen sizes larger than 600 pixels.
header {
background: #0580C3;
}
@media (min-width:600px) {
header {
margin: 0 ??% 0 0;
width: ???%;
float: left;
}
}
Where do you put your media queries??
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 (min-width:960px) {
.container {
width: 960px;
}
}
Sometimes our fluid grids are too small to fit our content nicely in our design at small screen sizes:
Fix your squished grid callout styles:
.callout { width: 100%; }
@media (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 (min-width:60em) {
.container {
width: 100%;
max-width: 960px;
}
}
Use multiple parameters to target in-between sizes (aka breakpoints)
@media (min-width:700px) and (max-width: 800px) {
.nav {
font-size: 110%;
}
}
Make your .content div yellow between 700 and 800 pixels wide only, and green above 800 pixels
@media (min-width:700px) and (max-width: 800px) {
.content {
background-color: green;
}
}
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 (min-width:60em) {
.container {
width: 100%;
max-width: 960px;
}
}
How do you know what breakpoint you're looking at??
These can be based on popular device sizes, like iPhone, iPad and desktop resolutions:
.container { width: 100%; }
@media (min-width:320px) {
.container {
margin: 0 auto;
width: 320px;
}
}
@media (min-width: 768px) {
.container {
width: 768px;
}
}
@media (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 (min-width:530px) {
.container {
float: left;
width: 41.6666666666667%; /* 400px/960px */;
}
}
Example: BohConf