23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

320-pixels-wide space.<br />

The general practice is to place all your full-screen landscape rules at the top of your <strong>CSS</strong> file and<br />

then make specific adjustments within the specific media queries. We did this with Here My Am! in<br />

Chapter 2, where the default styles worked for fullscreen-landscape and filled as-is, so we needed<br />

specific rules only for snapped and fullscreen-portrait.<br />

Tip When styling your app in Blend, there’s a visual affordance in the Style Rules pane that lets you<br />

control the exact insertion point of any new <strong>CSS</strong> styles in the given stylesheet. With this—the orange<br />

line shown in the graphic below and shown in Video 2-2 of the companion content—you can indicate<br />

where to insert styles for specific media queries and within that media query:<br />

In a few cases, handling media queries in declarative <strong>CSS</strong> alone won’t be sufficient. When the primary<br />

content display on a page is a horizontally panning ListView with GridLayout, you typically switch that<br />

control over to ListLayout in snapped view. You might also, as suggested on Guidelines for snapped and<br />

fill views, change a list of buttons to a single drop-down select element to offer the same functionality<br />

through a more compact UI. Such things require a little bit of JavaScript.<br />

For these purposes you can employ the standard Media Query Listener API in JavaScript. This<br />

interface (part of the W3C <strong>CSS</strong>OM View Module, see http://dev.w3.org/csswg/cssom-view/) allows you<br />

to add handlers for media query state changes. To listen for the snapped state, for instance, you can use<br />

code like this:<br />

246

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!