04.06.2013 Views

Head First HTML with CSS

Head First HTML with CSS

Head First HTML with CSS

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.

Step five:<br />

Finally, sort any conflicting rules in the order<br />

that they appear in their individual style sheets.<br />

We’re okay here, because we don’t have<br />

any conflicting rules at this point. The<br />

blueberry, <strong>with</strong> a score of 11, is the clear<br />

winner. If there had been two rules <strong>with</strong><br />

a score of 011, then the rule appearing<br />

latest would be the winner.<br />

We have a winner...<br />

After sweating through the first choice of elements, the<br />

sorting, more sorting, and being judged on specificity,<br />

the “h1.blueberry” rule has risen to the top. So the color<br />

property in the element will be blue.<br />

Q: So, one more time: I get that<br />

the lower in the <strong>CSS</strong> file the higher<br />

the precedence, but how does having<br />

multiple links to style sheets in my<br />

X<strong>HTML</strong> work?<br />

A: It’s always top to bottom, whether it<br />

is in the same <strong>CSS</strong> file or not. Just pretend<br />

that you inserted the <strong>CSS</strong> all together right<br />

into your file in the order the files are linked.<br />

That’s the order that counts.<br />

Q: So when you sort for specificity,<br />

you don’t re-sort everything?<br />

there are no<br />

Dumb Questions<br />

A: No. Think of each time you sort as<br />

refining what you’ve done before. So first<br />

you sort for author, reader, browser. Then,<br />

<strong>with</strong>in each of those sortings, you sort for<br />

specificity. And then, for any elements that<br />

have the same specificity, you sort again<br />

based on the ordering in the style sheets.<br />

Q: Do readers really make their own<br />

style sheets?<br />

A: By and large, no. But there are<br />

cases where people <strong>with</strong> visual impairments<br />

do, and of course you’ve always got the<br />

crowd that just has to tinker <strong>with</strong> everything.<br />

But, since each reader is controlling only<br />

how they see things, it really shouldn’t factor<br />

into your designs.<br />

h1.blueberry {<br />

color: blue;<br />

}<br />

h1 {<br />

color: #efefef;<br />

}<br />

body h1 {<br />

color: #cccccc;<br />

}<br />

h1 {<br />

color: black;<br />

}<br />

divs and spans<br />

Author<br />

Reader<br />

Browser<br />

Q: How much of this do I really need<br />

to remember?<br />

A: You’re going to develop some<br />

intuition for how all these style sheets fit<br />

together, and on a day to day basis that<br />

intuition will get you a long way. Every once<br />

in a while, though, you’ll see a style popping<br />

up in your pages that just boggles your<br />

mind, and that’s when you fall back on your<br />

training. You’ll be able to work through the<br />

cascade and before you know it, you’ll know<br />

exactly what’s happening in your page.<br />

you are here 479

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

Saved successfully!

Ooh no, something went wrong!