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.

168<br />

Adjacent selectors in an imperfect world<br />

Using an adjacent selector is my logical next step:<br />

p {<br />

margin: 0;<br />

}<br />

p+p {<br />

text-indent: 2.1em;<br />

}<br />

The p+p adjacent selector will address only a paragraph that is immediately preceded by another paragraph. In theory, this<br />

does exactly what I want it to, since the first paragraph is obviously not preceded by another paragraph, and will therefore<br />

ignore this rule. In a perfect world, this would have completed the task at hand, and I’d be at the bar by now. Sadly, though,<br />

Internet Explorer 6 does not support adjacent selectors, and now it renders all of my paragraphs as a single nebulous blob.<br />

When faced with a similar problem while I was putting together my personal site, I solved it like so:<br />

p {<br />

text-indent: 2.1;<br />

margin: 0;<br />

}<br />

h2+p {<br />

text-indent: 0;<br />

}<br />

The content area in question began with two headlines: a title (h1) and a date stamp (h2), followed by the first paragraph (p).<br />

The h2+p adjacent sibling selector achieved the desired effect in compliant browsers, and an indented first paragraph in<br />

Internet Explorer, a necessary compromise in a situation where the markup could not be altered.<br />

This is not a viable option in my current situation, since #main’s first paragraph is not preceded by another element, but<br />

there is also nothing stopping me from altering the markup ever so slightly. I need only to give the first paragraph a class of<br />

first:<br />

First paragraph copy goes here.<br />

And then add one more rule to my original CSS:<br />

p {<br />

text-indent: 2.1em;<br />

}<br />

.first {<br />

text-indent: 0;<br />

}<br />

Mission accomplished (Figure 7-12)!

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

Saved successfully!

Ooh no, something went wrong!