Media Queries
As mentioned at the beginning of this chapter, CSS3 includes a concept called media queries, which lets you assign styles to a page based on the width and height of the destination browser. So you can create custom styles for mobile phones, tablets, and desktop browsers, and, in turn, customize your site’s presentation so that it looks its best on each type of device. Because media queries are part of the yet-to-be-finished CSS3 standard, not all browsers support them. Fortunately, the browsers you’re most interested in—those for mobile phones and tablets—do, so even though Internet Explorer 8 doesn’t know what a media query is, your good old iPhone or Android device does.
Tip
You can make IE 8 and earlier understand your media queries by adding a bit of JavaScript to the <head> of your document. You’ll need to download the respond.js file from http://tinyurl.com/7w49a6z. Put the file in your site, and then link it to your page using the <script> tag. For example:
<script src="respond.min.js"></script>
This little maneuver forces IE 8, 7, and 6 to understand media queries. In fact, Dreamweaver CS6’s new Fluid Grid Layout automatically adds this JavaScript to your pages (see Adding Styles to Media Query Style Sheets).
A “query” is just a question asked of a web browser: “Is your screen 320 pixels wide?” If the answer is Yes, the browser launches a style sheet for just that size device (a style sheet that you supply, as explained on Using Dreamweaver’s Media Queries Tool ...
Get Dreamweaver CS6: The Missing Manual now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.