Quick Tip: A Crash-Course in CSS Media Queries
Tutorial Details
- Topic: CSS Media Queries
- Difficulty: Easy
- Estimated Completion Time: 4.5 Minute Screencast
In the past, in order to create layouts based upon the width of the user’s browser, we had to use JavaScript — perhaps combined with a server-side language. Fortunately, the process is now becoming far simpler, thanks to CSS media queries.
Subscribe to our YouTube page to watch all of the video tutorials!
Prefer to watch this video on Screenr?
Method 1: Within your Stylesheet
@media screen and (min-width : 1200px) {
/* let's do somethin' */
}
Method 2: Import from within your Stylesheet
@import url( small.css ) screen and ( min-width: 1200px );
Note that you can also add addition rules, by applying a comma — much like you would when using multiple selectors.
Method 3: Link to a Stylesheet
<link rel="stylesheet" media="screen and (min-width: 1200px)" href="small.css" />
Method 4: Targeting the iPhone
<link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="mobile.css" />
An interesting note, after a bit of research around the web, is that, despite the fact that iPhone 4 sports a resolution of 640×960, it still we pick up mobile.css, referenced in the code above. How strange? If you have more information on this, please leave a comment for the rest of us!
Browsers that Support CSS Media Queries
- Firefox 3.5+
- Opera 9.5+
- Safari 3+
- Chrome
- Internet Explorer 9+
Please note that Internet Explorer 8 and below do not support CSS media queries. In those cases, you should use a JavaScript fallback.
- Eduardo Barros
- http://www.russelluresti.com RussellUresti
- http://www.russelluresti.com RussellUresti
- http://www.russelluresti.com RussellUresti
- http://taylorhutchison.com Taylor Hutchison
- http://twitter.com/irengba irengba
- Anderson Juhasc
- Jeroen
- http://dmitry-scriptin.blogspot.com/ Scriptin
- Andy King
- GRolf
- http://www.material-designer.com Chris
- Brad
- http://linknomer.com andrei
- http://itvillage.site11.com It Village
- http://twitter.com/thimmpa Thim
- w1sh
- http://pixelcoder.co.uk Alistair
- http://net.tutsplus.com Jeffrey Way
- http://pixelcoder.co.uk Alistair
- Mike Hopley
- http://pixelcoder.co.uk Alistair
- cahva
- Jeffrey Way
- http://zubeta.com/beta/ 9swords
- http://www.eclipsedesign.eu Kartlos Tchavelachvili
- http://thedevelopertuts.com Bratu Sebastian
- http://mathiasbynens.be/ Mathias Bynens
- http://www.code.my devlim
- david
- http://www.webdesigncrap.info Gary
- http://www.esculent.co.uk Karl Munford
- Jerodq
- http://radio-pr.com/ Frank
- http://www.digitalfrontend.com Eduardo Martinez
- http://busybeeonabudget.com Jennifer
- http://www.sonnydesign.com sawebdesigns
- Emily
- http://www.codelabgh.com Joe
- saurabh
- JL
- Jey
- Jey
