jtcoders.github.io/responsive-web-design
RWD is a design approach that suggests that the design & development of a site shoud respond to the user's behavior and environment.
RWD modifies the presentation of a site, without modifying the content of the page. So no matter what, every user has access to the same information.
Fixed
Fluid
Wrappers are a good way to center content if the screen width is wider than your content.
.container {
width: 100%; /* take up full viewport width */
max-width: 1400px; /* if viewport is larger than 1440px,
don't let it take up 100% */
margin: 0 auto; /* center content in the viewport */
}
Text scales easily on smaller devices, but images are a bit tricky.
Images will overflow their container elements if they're too big for them.
That's annoying.
By using max-width on images, they will only expand to the size of their parent.
If their parent has no width, it will just expand to the width of the viewport.
img {
max-width: 100%;
}
Media queries apply certain CSS in certain situations.
They will overwrite previous styles because they are last in the cascade.
For devices that have dimensions no smaller than 320px and are not larger than 480px
/* Smartphones (portrait and landscape) */
@media only screen and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
iPad dimensions with the orientation in landscape.
/* iPads (landscape) ----------- */
@media only screen and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}
Rather than looking for a type of device, they look at the capability of the device. You can use them to check for all sorts of things.
By designing sites with mobile first in mind, it makes scaling them down a lot easier.
Mobile first allows us to simplify the user flow to its basic elements and then enhance it as the screen size increases.
BONUS: Change the order of the styles and queries to mobile-first.
Use this to control the size of the viewport.
<meta name="viewport" content="width=device-width,
initial-scale=1;">
width=device-width
makes the page width match the width of the device.
initial-scale=1
makes the browser not to zoom when changing orientation
More info in Google PageSpeed docs.
Retina screens have twice the pixel density than regular screens.
If you're not using SVG Graphics, you'll need two images, one for regular resolution and one for retina.
Target only retina screens by using this media query:
@media
(-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
/* Retina-specific stuff here */
}
This takes care of two things, 2x pixel ratio on iOS devices and "high res" Android screens.
Regular resolution icon
2x resolution icon
@media
(-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
.icon {
background-image: url(images/icon-2x.png) no-repeat 0 0;
background-size: 20px 20px;
}
}
Designers everywhere have always wanted to use vector based graphics on their sites because of their quality.
Well now you can!
It's been a W3C (World Wide Web Consortium) standard since 1999
In recent years browsers are becoming more and more compatable with SVG graphics.
Once upon a time, .png graphics weren't supported in browsers, soon the world will know about SVG!
Use Adobe Illustrator, or other vector program, to create a high quality image.
Save it as a .svg file.
Save a high res .png image as a fallback.
Use SVG as an image:
<img src="image.svg" onerror="this.onerror=null; this.src='image.png'">
Use SVG as a background image:
HTML:
<a href="/" class="logo">
GDI
</a>
CSS:
.logo {
display: block;
color: transparent;
width: 100px;
height: 82px;
background: url(kiwi.svg);
background-size: 100px 82px;
}
Our favorite topic - Internet Explorer
Chris Coyer has written an amazing article with tons of work arounds for our BFF IE8.