13.02.2013 Views

WEB STANDARDS CREATIVITY

WEB STANDARDS CREATIVITY

WEB STANDARDS CREATIVITY

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

A quick preview of our code at this point shows that not much has changed, except that we’ve lost part of our gray border<br />

(Figure 3-5).<br />

You may be asking, what in the name of Tim Berners-Lee is going on here? Or you might not be. We really don’t know.<br />

Figure 3-5. The layout is unchanged, but where’s our border off to?<br />

Clearing time<br />

Even though our two content divs don’t look drastically<br />

different than before, they are nonetheless floated elements,<br />

and as a result, they’ll “escape” from their nonfloated<br />

container, the content-layout div. So the<br />

border that we see at the top of our document is actually<br />

the whole border for content-layout: the two floated<br />

divs that it contains have simply flowed out of their parent,<br />

effectively completely collapsing our poor container.<br />

So content-layout now has no nonfloated elements to<br />

give it some height, and our lovely four-sided border just<br />

looks like a thick gray line. Naturally, this won’t do. But<br />

don’t start in quite yet with the gnashing of teeth and the<br />

pulling of hair. Thankfully, there’s a solution.<br />

To make sure that our container . . . well, contains the two<br />

columns, we’ll use the “Easy Clearing Method,” which is<br />

written up at http://positioniseverything.net/easyclearing.html.<br />

First, we place the following in our<br />

core.css file:<br />

#content-layout:after {<br />

content: ".";<br />

display: block;<br />

height: 0;<br />

clear: both;<br />

visibility: hidden;<br />

}<br />

Here we used the :after pseudo-element (www.w3.org/<br />

TR/CSS21/generate.html#x5) to generate extra content<br />

(namely, a period) at the end of our container, after all<br />

other elements. That extra content is then hidden from<br />

the user’s eye, but turned into a block-level element that<br />

will clear all other floats preceding it in the markup.<br />

Unfortunately, this rule won’t work in any current version<br />

of IE. And what’s more, to placate the Windows version of<br />

IE, we actually need two solutions: one for the latest version,<br />

7, which is a public beta at the time of this writing<br />

(but should be released properly by the time the book<br />

hits the shelves), and one that’s a hack for earlier versions<br />

currently in use.<br />

To make IE7 play nicely, we simply insert the following<br />

after our :after rule:<br />

#content-layout {<br />

display: inline-block;<br />

display: block;<br />

}<br />

To give credit where credit’s due, web designer and standards<br />

guru Roger Johansson (www.456bereastreet.<br />

com) was the one who first published this workaround<br />

(www.456bereastreet.com/archive/200603/<br />

new_clearing_method_needed_for_ie7). The display:<br />

inline-block; triggers the nonstandard hasLayout property<br />

in IE7, which forces the container to automatically<br />

contain any floated elements within it.<br />

chapter 3 New York Magazine: My, What a Classy <br />

59

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

Saved successfully!

Ooh no, something went wrong!