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.

size of the font.) Unfortunately, percentage values used in the font-size style in <strong>CSS</strong> are based on the<br />

default font size (1em), not the size of the parent element as happens with height and width. What<br />

you’d love to be able to do is something like font-size: calc(height * .4), but, well, the value of other<br />

<strong>CSS</strong> styles on the same element are just not available to calc.<br />

One exception to this is the vh value (which can be used with calc). If you know, for instance, that the<br />

text you want to scale is contained within a grid cell that is always going to be 10% of the viewport<br />

height, and if you want the font size to be half of that, then you can just use font-size: 5vh (5% of<br />

viewport height).<br />

Another method is to use an SVG for the text, wherein you can set a viewBox attribute and a<br />

font-size relative to that viewBox. Then scaling the SVG to a grid cell will effectively scale the font:<br />

<br />

<br />

Big SVG Text<br />

<br />

<br />

You can also use JavaScript to calculate the desired font size programmatically based on the<br />

clientHeight property of the parent element. If that element is in a grid cell, the font size (and line<br />

height) can be some percentage of that cell’s height, thereby allowing the font to scale with the cell.<br />

You can also try using the WinJS.UI.ViewBox control. If you want content like text to take up 50% of<br />

the containing element, wrap the ViewBox in a div that is styled to be 50% of the container and style<br />

the child element of the ViewBox with position: absolute. Try dropping the following code into<br />

default.html of a new Blank app project for a demonstration:<br />

<br />

<br />

Big text!<br />

<br />

<br />

Item Layout<br />

So far in this chapter we’ve explored page-level layout, which is to say, how top-level items are<br />

positioned on a page, typically with a <strong>CSS</strong> grid. Of course, it’s all just <strong>HTML</strong> and <strong>CSS</strong>, so you can use<br />

tables, line breaks, and anything else supported by the rendering engine so long as you adapt well to<br />

view states and display sizes.<br />

It’s also important to work with item layout in the flexible areas of your page. That is, if you set up a<br />

top-level grid to have a number of fixed-size areas (for headings, title graphics, control bars, etc.), the<br />

remaining area can vary greatly in size as the window size changes. In this section, then, let’s look at<br />

some of the tools we have within those specific regions: <strong>CSS</strong> transforms, flexbox, nested and inline grids,<br />

multicolumn text, <strong>CSS</strong> figures, and <strong>CSS</strong> connected frames. A general reference for these and all other<br />

262

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

Saved successfully!

Ooh no, something went wrong!