The Book of CSS3 - A Developer\'s Guide to the Future of Web Design (2nd edition)

(C. Jardin) #1
Selectors 29

Figure 3-4: The difference between the Adjacent Sibling and General Sibling Combinators

The paragraph elements  and x have neither bold nor italic rules
applied to them. Why not? Because element  precedes the h2, and ele-
ment x is inside a blockquote and, therefore, on a different level (the level
below) in the document tree, so neither is affected by the rules.
To achieve the desired effect of only italicizing the paragraphs on
the same level as the h2 element in CSS2, without the General Sibling
Combinator, you would need to set all p elements to display in italic and
then add an extra rule for the p inside the blockquote to overrule the
inheritance:

p { font-style: italic; }
blockquote p { font-style: normal; }

You probably won’t need to use the General Sibling Combinator often
because much of its function overlaps with the basic DOM selectors. That
said, you will still discover plenty of occasions where this combinator can
save you a little bit of code (and time).

Summary


Although attributes are a key feature of HTML4, most of them accept only
a limited range of values, so many of them do not really require the attri-
bute selectors I’ve introduced in this chapter. Aside from the href attribute,
only a handful of attributes accept more verbose values (alt, class, id, rel,
and title are the ones that spring to mind). But, as I mentioned before,
HTML5 introduces attributes like datetime and pubdate that allow you to be
more creative with selectors.
The new selectors introduced in this chapter, along with those from
previous versions of CSS, provide ways to apply style rules based on defined
Free download pdf