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.

specialized selectors<br />

#1 More Selectors<br />

While you’ve already learned the most common selectors, here are a few<br />

more you might want to know about...<br />

Pseudo-elements<br />

You know all about pseudo-classes, and pseudo-elements are similar. Pseudoelements<br />

can be used to select parts of an element that you can’t conveniently<br />

wrap in a or a or select in other ways. For example, the<br />

first-letter pseudo-element can be used to select the first letter of the<br />

text in a block element, allowing you to create effects like initial caps and<br />

drop caps. There’s one other pseudo-element called first-line, which<br />

you can use to select the first line of a paragraph. Here’s how you’d use<br />

both to select the first letter and line of a element:<br />

p:first-letter {<br />

font-size: 3em;<br />

}<br />

p:first-line {<br />

font-style: italic;<br />

}<br />

Attribute selectors<br />

img[width] { border: black thin solid; }<br />

640 Appendix<br />

Pseudo-elements use the same<br />

syntax as pseudo-classes.<br />

img[height=”300”] { border: red thin solid; }<br />

Here we’re making the first<br />

letter of the paragraph large,<br />

and the first line italics.<br />

Attribute selectors are not currently well supported in current<br />

browsers; however, they could be more widely supported in the<br />

future. Attribute selectors are exactly what they sound like: selectors<br />

that allow you to select elements based on attribute values. You use<br />

them like this: This selector selects all<br />

image[alt~=”flowers”] { border: #ccc thin solid; }<br />

This selector selects all images<br />

that have an alt attribute that<br />

includes the word “flowers”.<br />

images that have a width<br />

attribute in their X<strong>HTML</strong>.<br />

This selector selects all images<br />

that have a height attribute<br />

<strong>with</strong> a value of 300.

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

Saved successfully!

Ooh no, something went wrong!