• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 7. CSS Optimization > Use Simple Selectors and Substitution

Use Simple Selectors and Substitution

The selector part of a style rule is the link between your styles and your HTML elements. Selectors use pattern matching to determine which style rules apply to which elements in the document tree. Properly used, selectors can save you plenty of space and time tweaking pages. For the smallest CSS rules, use the simplest, highest DOM-hierarchy selectors you can, take advantage of inheritance, and group both selectors and declarations.

Use Type Selectors

Type selectors and the “universal” selector (*) are the simplest and most powerful selectors. “A type selector matches every instance of the element type in the document tree.”[1] For example,

[1] Bert Bos et al., “Chapter 5, Selectors,” in Cascading Style Sheets, level 2 CSS2 Specification [online], (Cambridge, MA:World Wide Web Consortium, 1998), available from the Internet at http://www.w3.org/TR/REC-CSS2/selector.html.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint