13.02.2013 Views

WEB STANDARDS CREATIVITY

WEB STANDARDS CREATIVITY

WEB STANDARDS CREATIVITY

SHOW MORE
SHOW LESS

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

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

58<br />

Furthermore, we apply min-width and max-width values to #wrap, ensuring that our design meets our client’s goal. The template’s<br />

width will expand in size until it reaches 980 pixels, and it will shrink down as far as 770 pixels. Looking sharp, no?<br />

Well, almost. There often is one blue “E”-shaped hiccup: versions 6 and below of Internet Explorer don’t support the maxwidth<br />

and min-width properties. A number of workarounds are available to us for IE on Windows. For New York Magazine,<br />

however, I settled on the following scrap of CSS:<br />

#wrap {<br />

width:expression(document.body.clientWidth > 980 ? "980px" : ➥<br />

(document.body.clientWidth < 772 ? "770px": "auto" ));<br />

}<br />

expression() is a dynamic property, which is a proprietary Microsoft invention (http://msdn.microsoft.com/workshop/<br />

author/dhtml/reference/methods/setexpression.asp) that works only in Internet Explorer on Windows. It muddies the<br />

otherwise clear waters between style sheets and scripting—as you can see, I’ve written a small snippet of JavaScript directly<br />

into the #wrap rule. When loaded by Internet Explorer, this JavaScript detects the width of the page (using<br />

document.body.clientWidth, another IE-only bit of code) and constrains the width of #wrap div if the window gets larger<br />

or smaller than our target widths.<br />

At this point, the standardistas in the audience might be asking, “But Ethan, why would you resort to nonstandard code<br />

in an otherwise standards-compliant template? And where do you live, so that I might throw pointed sticks at your<br />

W3C-hating house?”<br />

It’s at this point that our numerous CSS “patch” files come in handy. Since this is a fix for IE/Windows only, we can safely<br />

place the nonvalid code in our patches-win.iex.css file. Tucked away into this separate file, our nonstandard code is hidden<br />

from standards-compliant browsers and devices—and yes, that includes the beloved W3C CSS validator.<br />

Negative margins and columns and stuff! Oh my!<br />

With some markup and CSS foundations in place, it’s time to finish up our columns. Ryan Brill’s negative margins technique<br />

(http://alistapart.com/articles/negativemargins) is implemented in three simple steps:<br />

1. Set a width on the fixed-width sidebar (here, it’s content-secondary).<br />

2. Float the content-primary-wrap container to the left, and set its width to 100%.<br />

3. Set a negative margin-right on that container, the width of which should be equal to the width of the sidebar<br />

from step 1.<br />

The required CSS is as straightforward as it sounds. First, we need to float our two columns, like so:<br />

#content-primary-wrap {<br />

float: left;<br />

width: 100%;<br />

}<br />

#content-primary {<br />

padding: 0 12px 0 13px;<br />

}<br />

#content-secondary {<br />

float: right;<br />

}

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

Saved successfully!

Ooh no, something went wrong!