23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Finally, with both raster and vector images, there are file naming conventions that you use in<br />

conjunction with the .scale-100, .scale-140, and .scale-180 suffixes for pixel density. For contrast, the<br />

appropriate suffixes are .contrast-standard, .contrast-high, .contrast-black (black-on-white), and<br />

.contrast-white (white on black). We’ll see this in action in the second section below, “High Contrast<br />

Resources,” and see how to combine both the scaling and contrast suffixes in the third section, “Scale +<br />

Contrast = Resource Qualifiers.”<br />

<strong>CSS</strong> Styling for High Contrast<br />

The <strong>CSS</strong> styling for high contrast mode sample provides a valuable look at dealing with high contrast<br />

modes where media queries and image files are concerned. As you might expect, most of these features<br />

are demonstrated declaratively in <strong>CSS</strong> and the app’s resources; only one scenario actually has any<br />

JavaScript code at all!<br />

Scenario 1 shows the difference between elements that are and are not aware of contrast. With a<br />

normal color scheme in effect, its three buttons appear as follows, where the first two are div elements<br />

and the third a true button:<br />

When high contrast is turned on (Left Shift + Alt + Print Screen is very handy to toggle the setting for<br />

this sample), they appear like so:<br />

The first control, lacking contrast awareness, is still using white for its border, which of course<br />

disappears against a white background. The second button, on the other hand, has styles that use<br />

system-defined colors associated with a high contrast media query, so the button works well with any<br />

theme (css/scenario1.css):<br />

@media (-ms-high-contrast) {<br />

.s1-hc {<br />

background-color: ButtonFace;<br />

color: ButtonText;<br />

border: 1px solid ButtonText;<br />

}<br />

/* ... */<br />

}<br />

Tip If you just stick with system colors entirely, both in <strong>CSS</strong> and in SVGs, then you won’t need to use<br />

media queries or different SVG files at all, because those colors will be adjusted for high contrast modes<br />

automatically. See User-defined system colors for a reference. You can also use the current-Color<br />

value in SVGs for fill, stroke, stop-color, flood-color, and lighting-color properties to reflect<br />

contrast settings.<br />

790

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

Saved successfully!

Ooh no, something went wrong!