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.

Scenario 2 of the <strong>HTML</strong> Appbar Control sample shows many such selectors in action, in this case to<br />

set the background of the app bar and its commands to blue and the foreground color to green (a<br />

somewhat hideous combination, but demonstrative nonetheless).<br />

As a basis, Scenario 2 (html/custom-color.html) adds a <strong>CSS</strong> class customColor to the app bar:<br />

<br />

In css/custom-color.css it then styles selectors based on .win-appbar.customColor. The following<br />

rules, for instance, set the overall background color, the label text color, and the color of the circle<br />

around the commands for the :hover and :active states:<br />

.win-appbar.customColor {<br />

background-color: rgb(20, 20, 90);<br />

}<br />

.win-appbar.customColor .win-label {<br />

color: rgb(90, 200, 90);<br />

}<br />

.win-appbar.customColor button:hover .win-commandring,<br />

.win-appbar.customColor button:active .win-commandring {<br />

background-color: rgba(90, 200, 90, 0.13);<br />

border-color: rgb(90, 200, 90);<br />

}<br />

All of this styling, by the way, applies only to the standard command-oriented layout. If you’re using<br />

a custom layout, the app bar just contains whatever elements you want with whatever style classes you<br />

want, so you just handle styling as you would any other <strong>HTML</strong>.<br />

Custom Icons<br />

Earlier we saw that the icon property of an AppBarCommand typically comes from the Segoe UI Symbol<br />

font. Although this is suitable for most needs, you might want at times to use a character from a<br />

different font (some of us just can’t get away from Wingdings!) or to provide custom graphics. The app<br />

bar supports both.<br />

To use a different font for the whole app bar, simply add a class to the app bar and create a rule<br />

based on win-appbar:<br />

win-appbar.customFont {<br />

font-family: "Wingdings";<br />

}<br />

To change the font of a specific command button, add a class to its extraClass property (such as<br />

customButtonFont) and create a rule with the following selector (as used in Scenario 1 of the modified<br />

sample):<br />

button.customButtonFont .win-commandimage {<br />

font-family: "Wingdings";<br />

}<br />

288

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

Saved successfully!

Ooh no, something went wrong!