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.

Q: Okay, I think I get all this, and<br />

it was kind of fun having the validator<br />

check my <strong>HTML</strong>, but SO WHAT? Again,<br />

what is all this “compliance” really<br />

getting me?<br />

A: How does happier customers<br />

sound? If you know your <strong>HTML</strong> is valid,<br />

then it’s more likely that your Web pages<br />

will work consistently in a wide variety of<br />

browsers, which is going to give your Web<br />

page users a better experience. There<br />

are a few other benefits: Web pages <strong>with</strong><br />

compliant <strong>HTML</strong> load faster and work<br />

better on other devices that are now<br />

being used to surf the Web (like TVs and<br />

phones). They’re also more accessible to<br />

the visually impaired who are using aural<br />

screen readers.<br />

Q: So can you explain the error in<br />

detail? I want to understand exactly<br />

what it means.<br />

A: The error was caused by the<br />

element not being nested inside<br />

a block element. Imagine the browser is<br />

reading through your <strong>HTML</strong>, and sees<br />

an element where it expected<br />

Exercise<br />

there are no<br />

Dumb Questions<br />

a block element. The first thing it does<br />

is say, “Hey, I expected a block element<br />

here.” It keeps reading, and then gets to<br />

the end of the element (which,<br />

since is an empty element,<br />

happens as soon as it sees the “>” at the<br />

end of the tag) and says, “Hey<br />

you can’t be ending an element<br />

here because there shouldn’t be an<br />

element here to start <strong>with</strong>.”<br />

Also, you might find that you see multiple<br />

error messages from one mistake. Just<br />

take it one error message at a time, fix<br />

your mistake, and you’ll often find you<br />

eliminate more than one error message in<br />

the process.<br />

Q: Are all the validator’s error<br />

messages so difficult to understand?<br />

A: Generally, yes, the error<br />

messages can be a little difficult to<br />

decipher. This is a piece of software<br />

telling you what is wrong, not a human<br />

or a <strong>Head</strong> <strong>First</strong> book. Remember, the<br />

validator doesn’t know what you meant to<br />

do and can only attempt to decipher and<br />

indicate errors in what you actually did.<br />

Most of the time, it will point you to the<br />

right line in your <strong>HTML</strong> where your error<br />

is occurring, which is half the battle. Then<br />

standards, compliance, and all that jazz<br />

hopefully you’ll spot your mistake.<br />

After reading these error messages for a<br />

while you’ll start to get the hang of them<br />

and often know what they are referring<br />

to, even if the validator doesn’t tell you<br />

specifically.<br />

Q: Why are all the element<br />

names listed in that error message in<br />

uppercase? I thought element names<br />

were written in lowercase.<br />

A: Good question. <strong>HTML</strong> actually<br />

allows element names to be uppercase<br />

or lowercase, or even mixed case. You<br />

could write or even if you<br />

wanted. However, the W3C is changing<br />

the rules, so in the future element names<br />

will all be lowercase. So, while technically<br />

the validator for Strict <strong>HTML</strong> 4.01 still<br />

allows (and displays) uppercase tags,<br />

we’re only using lowercase so you’ll get<br />

into the habit of using only lowercase.<br />

This means you won’t have to update your<br />

tag names down the road (and that means<br />

less work for you). And when we say<br />

“down the road,” we actually mean in the<br />

next chapter.<br />

Your turn. Add the strict DOCTYPE and the tag to<br />

“directions.html” and “elixir.html”. Try validating them – do<br />

they validate? If not, fix them so that they do.<br />

you are here 251

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

Saved successfully!

Ooh no, something went wrong!