04.06.2013 Views

Head First HTML with CSS

Head First HTML with CSS

Head First HTML with CSS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

owsers and quirks mode<br />

<strong>Head</strong> <strong>First</strong>: We’re glad to have you here, Browser.<br />

As you know, “<strong>HTML</strong> versions” have become a<br />

popular issue. What’s the deal <strong>with</strong> that? You’re a<br />

Web browser after all. I give you <strong>HTML</strong> and you<br />

display it the best you can.<br />

Browser: Being a browser is tough these days...<br />

there are a lot of Web pages out there and many are<br />

written <strong>with</strong> old versions of <strong>HTML</strong> or <strong>with</strong> mistakes<br />

in their markup. Like you said, my job is to try to<br />

display every single one of those pages, no matter<br />

what.<br />

<strong>Head</strong> <strong>First</strong>: So what’s the big deal? What does it<br />

really matter which version of <strong>HTML</strong> I use?<br />

Browser: Remember the browser wars? All kinds<br />

of elements were added to <strong>HTML</strong> that we aren’t<br />

supposed to use anymore. But some people expect us<br />

browsers to be able to display them anyway, and we<br />

don’t always agree on how that should be done.<br />

<strong>Head</strong> <strong>First</strong>: Why aren’t we supposed to use those<br />

elements any more?<br />

Browser: Well, before <strong>CSS</strong> was invented, <strong>HTML</strong><br />

had elements that were there for presentation, not<br />

structure. Now, <strong>with</strong> <strong>CSS</strong>, we don’t need those<br />

anymore, but there are still plenty of Web pages out<br />

there that use them.<br />

<strong>Head</strong> <strong>First</strong>: I think I’m starting to see the problem.<br />

So how do you manage to display all these pages in<br />

all these different versions of <strong>HTML</strong>? That’s quite a<br />

tall order.<br />

Browser: Yeah, like I said, it’s tough being a<br />

browser. What we end up doing is having two sets of<br />

rules for displaying Web pages: one for old <strong>HTML</strong><br />

and one for the newer, standard <strong>HTML</strong>. When I use<br />

the old rules, I call that my “quirks mode” because<br />

228 Chapter 6<br />

The Browser Exposed<br />

This week’s interview:<br />

Why do you care which version<br />

of <strong>HTML</strong> you’re displaying?<br />

there are so many weird things that can happen on<br />

those pages.<br />

<strong>Head</strong> <strong>First</strong>: That sounds like a pretty good<br />

solution to me...<br />

Browser: Well, it can get you into trouble, though.<br />

If you’re writing new <strong>HTML</strong>, but you don’t tell me<br />

you’re writing new <strong>HTML</strong>, then I have to assume<br />

you’re writing old <strong>HTML</strong>, and go into quirks mode<br />

just in case. And you don’t want that.<br />

<strong>Head</strong> <strong>First</strong>: What do you mean?<br />

Browser: Not all browsers agree on how to display<br />

the older stuff, but we all do a pretty consistent job<br />

<strong>with</strong> standard <strong>HTML</strong>. So if you’re using standard<br />

<strong>HTML</strong>, tell me and you’ll get more consistent results<br />

in all browsers.<br />

<strong>Head</strong> <strong>First</strong>: Oh, so you can end up using the<br />

quirks mode rules on the pages written using new<br />

<strong>HTML</strong>?<br />

Browser: Exactly. If I don’t know you’re writing<br />

new <strong>HTML</strong>, I go into my quirks mode and do the<br />

best I can. But, you don’t want that because all those<br />

“quirks” mean that your pages might end up looking<br />

a bit off, when they could have looked beautiful if I’d<br />

only known you were using new <strong>HTML</strong>.<br />

<strong>Head</strong> <strong>First</strong>: Ahh. So, what’s the solution to this<br />

mess? We definitely want our Web pages to look<br />

good.<br />

Browser: Easy. Tell me up front which version of<br />

<strong>HTML</strong> you’re using. That way I know which rules<br />

to use to display your page.<br />

<strong>Head</strong> <strong>First</strong>: Got it. Thank you, Browser!

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

Saved successfully!

Ooh no, something went wrong!