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.

more on pseudo-classes<br />

470 Chapter 11<br />

<strong>Head</strong> <strong>First</strong>: Welcome, Pseudo-class. It’s a<br />

pleasure to have you here. I must confess that<br />

when they first asked me to do this interview,<br />

I drew a blank. Pseudo-class? The only thing<br />

that came to mind was that ’80s Phil Collins<br />

song.<br />

Pseudo-class: Uh, that would be Sussudio.<br />

My name is Pseudo.<br />

<strong>Head</strong> <strong>First</strong>: Oops. Honest mistake.<br />

Maybe we could start there. Can you tell us<br />

a little about where Pseudo came from?<br />

Pseudo-class: Pseudo usually means<br />

something that looks like the real thing, but<br />

isn’t.<br />

<strong>Head</strong> <strong>First</strong>: And the last name? Class?<br />

Pseudo-class: Everyone knows what a<br />

<strong>CSS</strong> class is. It’s a grouping you create to<br />

place elements in so you can style them<br />

together. Put “pseudo” and “class” together<br />

and you have a pseudo-class: it acts like a<br />

class, but it isn’t a real class.<br />

<strong>Head</strong> <strong>First</strong>: What’s not real about it if it<br />

acts like a class?<br />

Pseudo-class: Okay, open up an X<strong>HTML</strong><br />

file and look for the class :visited, or :link, or<br />

:hover. Let me know when you find one.<br />

<strong>Head</strong> <strong>First</strong>: I don’t see any.<br />

Pseudo-class: And yet, a:link, a:visited,<br />

and even a:hover all allow you to specify<br />

style, just like they were classes. So, those are<br />

pseudo-classes. In other words, you can style<br />

pseudo-classes, but no one ever types them<br />

into their X<strong>HTML</strong>.<br />

<strong>Head</strong> <strong>First</strong>: Well then, how do they work?<br />

The Pseudo-class Exposed<br />

This week’s interview: getting to know the<br />

pseudo-class.<br />

Pseudo-class: You can thank your browser<br />

for that. The browser goes through and adds<br />

all your elements to the right pseudoclasses.<br />

If a link’s been visited, no problem;<br />

it goes into the “visited” class. Is the user<br />

hovering over a link? No problem, the<br />

browser throws it in the “hover” class. Oh,<br />

now the user isn’t hovering? The browser<br />

yanks it out of the “hover” class.<br />

<strong>Head</strong> <strong>First</strong>: Wow, I never knew. So there<br />

are all these classes out there that the browser<br />

is adding and removing elements from<br />

behind the scenes.<br />

Pseudo-class: That’s right, and it’s<br />

damned important to know about, otherwise<br />

how would you give your links style that<br />

adapted to what state the link was in?<br />

<strong>Head</strong> <strong>First</strong>: So, Pseudo, do you just do<br />

links?<br />

Pseudo-class: No, I do other elements<br />

too. Some browsers already support pseudoclasses<br />

like active and hover on other types of<br />

elements. And there are some other pseudoclasses,<br />

too. For instance, the pseudo-class<br />

:first-child is assigned to the first child of<br />

any element, like the first paragraph in<br />

a . But be careful on<br />

everything other than :link, :visited, and<br />

:hover because browser support isn’t fully<br />

there yet.<br />

<strong>Head</strong> <strong>First</strong>: Well, I’ve certainly learned<br />

something in this interview. Who knew that<br />

song was actually called “Sussudio”?! Thanks<br />

for being here Pseudo-class.

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

Saved successfully!

Ooh no, something went wrong!