WEB STANDARDS CREATIVITY
WEB STANDARDS CREATIVITY
WEB STANDARDS CREATIVITY
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
218<br />
There are two major changes between the two layouts:<br />
The content in the larger style is presented in four<br />
columns across the page, whereas the smaller<br />
style keeps the content in one column. A four-column<br />
layout better uses the space at higher<br />
resolutions and reduces the height of the page. At<br />
smaller screen sizes, the columns become too narrow<br />
to be useful, and so the single column<br />
produces better content width.<br />
The menus are positioned differently. When using<br />
a horizontal menu, we often run into problems on<br />
smaller screens as the number of menu items<br />
increases. Eventually, they will wrap onto two lines.<br />
To combat this, we change the orientation of the<br />
menu from horizontal to vertical and position it<br />
next to the content.<br />
Both of these changes can be achieved relatively easily<br />
using CSS, by modifying widths and floating elements. For<br />
example, at 800✕600, each of the three main content<br />
panels uses its default browser styling: a block element<br />
spanning 100% of its container. To get them to line up side<br />
by side in the 1024✕768 style sheet, we make them float<br />
left and supply a width:<br />
.panel<br />
{<br />
float: left;<br />
width: 26.5%;<br />
}<br />
Both layouts use exactly the same HTML markup contained<br />
in resolution.htm, so the style sheet changes are<br />
the only ones you need to make.<br />
Because an alternate style sheet is additive to the main<br />
style sheet, we go ahead and code the 800✕600 style<br />
sheet as we would normally—it will be applied no matter<br />
what. To get our alternate wider style sheet, we extended<br />
the basic styles. We don’t need to write an entirely new<br />
style sheet; we’re just modifying and adding to the styles<br />
that already exist.<br />
As you’ll see in the downloadable files for this example,<br />
the basic style sheet, main.css, weighs in at (a nicely<br />
spaced) 442 lines. The alternate style sheet, wide.css, is<br />
considerably smaller, at 190 lines.<br />
To include both style sheets on our page, we use link<br />
elements:<br />
<br />
<br />
The main style sheet’s rel attribute is set to stylesheet,<br />
so it will be applied to the page automatically. By setting<br />
the alternate style sheet’s rel attribute to alternate<br />
stylesheet, we indicate to the browser that it shouldn’t<br />
be applied unless specified. It’s also important to include<br />
a title attribute for the alternate style sheet, so we can<br />
identify it later.<br />
But how do we go about turning on the alternate style<br />
sheet when we need it?<br />
Turning on the style<br />
We have a few options for offering this new resolutiondependent<br />
style sheet to users, most of which are pretty<br />
ineffectual:<br />
Include the alternate style sheet in the HTML and<br />
hope that the user is using a browser that allows<br />
switching between alternate style sheets, and also<br />
realizes that there is an alternate style sheet, and<br />
then will bother to turn it on if it applies to him<br />
(ain’t gonna happen).<br />
Use an in-page style sheet switcher. Create a<br />
widget on every page that allows the user to specify<br />
what style she would like the page to be viewed<br />
in (just like the one described by Paul Sowden in<br />
his article on A List Apart, http://alistapart.<br />
com/stories/alternate/). It’s a bit like the native<br />
browser option, except it’s more visible and is<br />
accessible to more browsers. However, in my<br />
experience, users aren’t going to go out of their<br />
way to change the default appearance of a page,<br />
even if it’s going to benefit them.<br />
Do it automatically. Supply the wider style sheet to<br />
browsers that can handle it. Give the users the best<br />
experience without them having to lift a finger.