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.

Fonts and Text Overflow<br />

As discussed earlier, typography is an important design element for Store apps, and for the most part<br />

the standard font styles using Segoe UI are already defined in the default WinJS stylesheets. In the<br />

Windows SDK there is a very helpful <strong>CSS</strong> typography sample that compares the <strong>HTML</strong> header elements<br />

and the win-type-* styles, demonstrating font fallbacks and how to use bidirectional fonts (left to right<br />

and right to left directions).<br />

Speaking of fonts, custom font resources using the @font-face rule in <strong>CSS</strong> are allowed in Store apps.<br />

For local context pages, the src property for the rule must refer to an in-package font file (that is, a URI<br />

that begins with / or ms-appx:///). Pages running in the web context can load fonts from remote<br />

sources.<br />

Another piece of text and typography is dealing with text that overflows its assigned region. You can<br />

use the <strong>CSS</strong> text-overflow: ellipsis; style to crop the text with a …, and the WinJS stylesheets contain<br />

the win-type-ellipsis class for this purpose. In addition to setting text-overflow, this class also adds<br />

overflow: hidden (to suppress scrollbars) and white-space: nowrap. It’s basically a style you can add to<br />

any text element when you want the ellipsis behavior.<br />

The W3C specification on text overflow, http://dev.w3.org/csswg/css3-ui/#text-overflow, is a helpful<br />

reference as to what can and cannot be done here. One of the limitations of the current spec is that<br />

multiline wrapping text doesn’t work with ellipsis. That is, you can word-wrap with the word-wrap:<br />

break-word style, but it won’t cooperate with text-overflow: ellipsis (word-wrap wins). I also<br />

investigated whether flowing text from a multiline <strong>CSS</strong> region (see next section) into a single-line region<br />

with ellipsis would work, but text-overflow doesn’t apply to regions. So at present you’ll need to<br />

shorten the text and insert ellipsis manually if it spans multiple lines.<br />

For a demonstration of ellipsis and word-wrapping, see the CenteredText example for this chapter.<br />

266

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

Saved successfully!

Ooh no, something went wrong!