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.

there are no<br />

Dumb Questions<br />

Q: That wasn’t too bad; I was expecting pages<br />

of rules I had to remember. Can I really write strict<br />

<strong>HTML</strong> 4.01 just following these rules?<br />

A: These rules will get you a long way, but<br />

remember, you haven’t learned everything about <strong>HTML</strong><br />

yet, so there are going to be a few new things that<br />

you’ll need to keep in mind too. That said, there is no<br />

reason to memorize all these rules. Your common<br />

sense and this guide is a good start, and from there<br />

you can also consult an <strong>HTML</strong> reference or just ask the<br />

validator if your <strong>HTML</strong> is valid (you should anyway!)<br />

when you get into some tricky areas.<br />

Q: So whenever possible, always go <strong>with</strong><br />

strict?<br />

A: It depends. Just throwing up a page that three<br />

people in the world will see? Hey, as long as it looks<br />

good in all your browsers, who cares. But if you’re<br />

doing something a fair number of people will visit,<br />

you’ll be better off keeping your <strong>HTML</strong> up to standards<br />

and validating it. Should that be the transitional or<br />

strict standard? Well, the world is moving in the<br />

strict direction, so you can pay now or pay later, but<br />

eventually, it will be in your best interest to go strict.<br />

When you’re starting fresh, strict is just as easy. And<br />

if you use strict, moving to X<strong>HTML</strong> will be a lot easier,<br />

and we’re going to do that in the very next chapter and<br />

use X<strong>HTML</strong> in the rest of the book.<br />

Q: So I get that putting an inside an <br />

is confusing and wouldn’t work anyway. But I can<br />

really put an inside an ? What’s the<br />

point of that?<br />

A: In principle, someone might want to put<br />

emphasis on emphasis. That seems silly, but since it<br />

doesn’t cause problems, like nested elements<br />

do, the standard just says, if you want to do it, you<br />

can. What about a <strong>with</strong>in a , would that ever<br />

make sense? Sure, you might quote someone who<br />

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

quotes someone else. So, in general you can nest<br />

any of the inline elements inside other inline elements.<br />

Some of these make more sense than others, but the<br />

element is the only one that you can’t nest inside<br />

itself. Remember too, that the element is<br />

empty, so you can’t nest anything inside it.<br />

Q: So why can’t I put text directly in a<br />

? A list item can have text or a block<br />

element. That seems inconsistent.<br />

A: ’Cause the standard says so. Just kidding.<br />

You’re right, it does seem inconsistent, but it’s all<br />

based on the intent of the element. Take the <br />

element, for instance. It’s for one text paragraph, so<br />

of course no other block elements are allowed in it.<br />

? It’s for quoting large portions of text<br />

from another source, which might include headings,<br />

paragraphs, whatever. So the point is to “quote<br />

blocks.” List items? They’re like the contortionists of<br />

the element world – they have to be able to hold simple<br />

text, large bits of text like paragraphs or even other<br />

lists, so they can handle everything.<br />

Q: I noticed the validator said<br />

the standard requires the “alt”<br />

attribute on elements. Are<br />

there any other attributes that are<br />

required?<br />

A: Wow, good catch. Yes, the alt attribute<br />

is required on images for accessibility, so that, for<br />

instance, the visually impaired can know what the<br />

image is, even if they can’t see it. The other required<br />

attribute is the src attribute on an image – what good<br />

is an element if it doesn’t point to an image?<br />

There are also some attributes that were okay <strong>with</strong><br />

<strong>HTML</strong> 3.2 that you can’t use anymore <strong>with</strong> strict <strong>HTML</strong><br />

4.01. Why? Because most of them affected the way<br />

Web pages looked, and you’re supposed to be using<br />

<strong>CSS</strong> for that kind of styling (more on this topic in just a<br />

couple of chapters).<br />

Webville’s a friendly<br />

place. Forget a rule? Just<br />

run it by me, the Validator.<br />

I’ll get you pointed in the<br />

right direction.<br />

Validator<br />

you are here 255

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

Saved successfully!

Ooh no, something went wrong!