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.

Q: So, a acts like a container<br />

that you can put elements into to keep<br />

them all together?<br />

A: It sure does. In fact, we often<br />

describe s as “containers”. Not only<br />

do they act as logical containers that you<br />

can use to hold a bunch of related elements<br />

(like the “cat” elements) together, but when<br />

we start styling s and using them for<br />

positioning in the next chapter, you’ll see<br />

they act as graphical containers, too.<br />

Q: Beyond the structure I’m already<br />

putting into my pages <strong>with</strong> headings and<br />

paragraphs and so on, should I also be<br />

adding a higher level of structure <strong>with</strong><br />

s?<br />

A: Yes and no. You want to add<br />

structure where it has a real purpose, but<br />

don’t add structure for structure’s sake.<br />

Always keep your structure as simple as<br />

possible to get the job done. For instance,<br />

there are no<br />

Dumb Questions<br />

if it is helpful to add a “pets” section<br />

that contains both “cats” and “dogs” to<br />

the PetStorz page, by all means add it.<br />

However, if it provides no real benefit, then<br />

it just complicates your page. After working<br />

<strong>with</strong> s for a while, you’ll start to get a<br />

feel for when and how much to use them.<br />

Q: Do you ever put s in a class<br />

instead of giving it an id?<br />

A: Well, remember that an element can<br />

have an id and be in one or more classes at<br />

the same time, so the choice isn’t mutually<br />

exclusive. And, yes, there are many times<br />

you create s and place them into<br />

classes. Say you have a bunch of album<br />

sections in a page of music playlists; you<br />

might put all the elements that make up the<br />

album into a and then put them all in a<br />

class called “albums”. That identifies where<br />

the albums are, and they can all be styled<br />

together <strong>with</strong> the class. At the same time<br />

you might give each album an id so that it<br />

can have additional style applied separately.<br />

divs and spans<br />

Q: I was having a little trouble<br />

following the <strong>with</strong>in stuff,<br />

<strong>with</strong> the “pets” and “cats” and “dogs”.<br />

Could you explain that a little more?<br />

A: Sure. You’re used to elements being<br />

nested in other elements, right? Like a <br />

nested in a nested in an <br />

element. You’ve even seen lists nested<br />

<strong>with</strong>in lists. The is really no different;<br />

you’re just nesting an element inside another<br />

element, and, in the case of PetStorz, we’re<br />

using it to show larger chunks of structure<br />

(a “cats” and “dogs” nested in a “pets”<br />

section). Or, you might use s to have a<br />

beer section nested in a beverages section<br />

nested in a menu section.<br />

But, the best way to understand why you’d<br />

want something like a <strong>with</strong>in a is<br />

by using them and encountering a situation<br />

where they mean something to you. Put this<br />

in the back of your mind and you’ll see an<br />

example soon enough where we need one.<br />

Use, don’t abuse, s in your pages. Add additional<br />

structure where it helps you separate a page into logical<br />

sections for clarity and styling. Adding s just for<br />

the sake of creating a lot of structure in your pages<br />

complicates them <strong>with</strong> no real benefit.<br />

you are here 437

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

Saved successfully!

Ooh no, something went wrong!