Professional Documents
Culture Documents
info
Selectors, Specificity,
and the Cascade
Eric A. Meyer
www.it-ebooks.info
Selectors, Specificity, and the Cascade
by Eric A. Meyer
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (http://my.safaribooksonline.com). For more information, contact our
corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com.
Editors: Simon St. Laurent and Meghan Blanchette Cover Designer: Karen Montgomery
Production Editor: Kristen Borg Interior Designer: David Futato
Copyeditor: Rachel Leach Illustrator: Robert Romano
Proofreader: O’Reilly Production Services
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. Selectors, Specificity, and the Cascade, the image of a salmon, and related trade dress
are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume
no responsibility for errors or omissions, or for damages resulting from the use of the information con-
tained herein.
ISBN: 978-1-449-34249-4
[LSI]
1348246251
www.it-ebooks.info
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
1. Selectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Basic Style Rules 1
Element Selectors 2
Declarations and Keywords 3
Grouping 4
Grouping Selectors 5
Grouping Declarations 6
Grouping Everything 7
Class and ID Selectors 9
Class Selectors 9
Multiple Classes 11
ID Selectors 13
Deciding Between Class and ID 14
Attribute Selectors 15
Simple Attribute Selectors 15
Selection Based on Exact Attribute Value 16
Selection Based on Partial Attribute Values 18
A Particular Attribute Selection Type 21
Using Document Structure 22
Understanding the Parent-Child Relationship 22
Descendant Selectors 24
Selecting Children 27
Selecting Adjacent Sibling Elements 28
Selecting Following Siblings 30
Pseudo-Class Selectors 31
Combining Pseudo-Classes 31
Structural Pseudo-Classes 31
Dynamic Pseudo-Classes 43
UI State Pseudo-Classes 47
The :target Pseudo-Class 49
iii
www.it-ebooks.info
The :lang Pseudo-Class 50
The Negation Pseudo-Class 51
Pseudo-Element Selectors 53
Styling the First Letter 54
Styling the First Line 55
Restrictions on ::first-letter and ::first-line 55
Styling (Or Creating) Content Before and After Elements 56
Summary 56
iv | Table of Contents
www.it-ebooks.info
Preface
www.it-ebooks.info