Presented by Peter Traeg / @ptraeg
Peter Traeg
Solutions Architect, Universal Mind
iOS, Android, and Web Developer
Slides / Code: http://traeg.org
Twitter: @ptraeg
About Universal Mind:
Ethan Marcotte - A List Apart - Responsive Web Design
Luke Wroblewski:
Design from the core needs of a mobile user first. Then augment that experience as more screen real estate becomes available.
Commonly used to detect browser width, device-width,
and pixel density
@media screen and (min-width:480px) {
⋮ one or more rule sets…
}
Note that multiple conditions can be tested and media features prefixed with min- or max-
@media screen and (min-width: 45em) {
.mindshare-listings, .news-listings {
width: 50%;
float: left;
position: relative;
border-right: 1px dashed #d9d9d9;
padding-right: 1.5em;
margin-top: 0.5em;
}
}
Displays MindShare content at 50% width if browser width > 720px (45em)
- or -
@import url(/medium-width.css) screen and (min-width:800px) and (max-width:1280px);
- or -
The viewport meta tag
Without this most mobile browsers will use a screen width of 980px.
Min / Max scale
Preventing scale
Generally preventing user scaling of your page should be avoided, but is sometimes used to with Mobile Safari to prevent the page zooming in when you rotate to landscape orientation.
.sideBarContent {
background-image: url(images/golden_gate_800.jpg);
}
/* Responsive section */
@media screen and (min-width:480px) and (max-width: 800px) {
.sideBarContent {
display: none;
}
}
Even if the screen size causes the display:none to be active remember that all the content in that container will still be fetched (images, etc.). It just won't be displayed. This is an issue for mobile users if your page contains lots of content that will be hidden for mobile users.
Media queries are not supported
prior to IE9
Load a style sheet that would normally be used for desktop browsers.
Adds limited media query support for browsers that don't support them.
Note Respond.js supports only min-width and max-width media queries.
@media screen and (min-width: 480px){
...styles for 480px and up go here
}
Obviously this adds some overhead as the JS file must be loaded and the CSS file parsed before IE can continue. Conditional comments may be more performant, if not less flexible.
More techniques available on Smashing Magazine.
Test media queries from within Javascript
if (window.matchMedia("(min-width: 400px)").matches) {
/* the view port is at least 400 pixels wide */
} else {
/* the view port is less than 400 pixels wide */
}
Or use properties like
window.innerWidth and window.devicePixelRatio
Support: window.matchMedia is supported in IE10 and later.
Most responsive grid systems require all columns to add up to 12.
The following frameworks all offer a responsive grid:
Extra small devices | Small devices | Medium devices | Large devices | |
---|---|---|---|---|
Grid behavior | Horizontal at all times | Collapsed to start, horizontal above breakpoints | ||
Max container width | None (auto) | 750px | 970px | 1170px |
Class prefix |
.col-xs-
|
.col-sm-
|
.col-md-
|
.col-lg-
|
# of columns | 12 |
@media screen and (min-width: 45em) {
.mindshare-listings, .news-listings {
width: 50%;
float: left;
position: relative;
border-right: 1px dashed #d9d9d9;
padding-right: 1.5em;
margin-top: 0.5em;
}
}
Displays MindShare content at 50% width if browser width > 720px (45em)
Sometimes just loading a different size image isn't enough
The following techniques involve using CSS to swap the background-image url based on the device DPI.
Proposal of: RICG - Responsive Images Community Group
These solutions have a server based component to deliver the image file at the proper resolution.
All the content that fits... we show.
Load as you go.
Slides / Code: http://traeg.org
Twitter: @ptraeg