In this chapter, you’ll learn how to shrink your style sheets and HTML at the same time. CSS-specific techniques include (1) grouping declarations and selectors, (2) merging common styles into shared classes, (3) inheritance, (4) abbreviating with shorthand properties, and (5) abbreviating class and ID names. HTML-oriented techniques include replacing JavaScript behavior with CSS, designing markup for descendant selectors, and CSS layout. By combining these techniques, you can reduce HTML and CSS file sizes by up to 50%. When you plan your site in this way you are giving it what we call CSS architecture.
To maximize display speed you can employ the following ten techniques:
- CSS Optimization
- Build on a CSS Architecture
- Anatomy of a CSS Rule (sidebar)
- Use a Reset Stylesheet
- Top 10 Tips for Optimizing CSS
- Tip #1: Replace Inline Style with Type Selectors
- Tip #2: Use Descendant Selectors
- Tip #3: Group Selectors with Common Declarations
- Tip #4: Group Declarations with Common Selectors
- Tip #5: Combine Common Styles into Shared Classes
- Tip #6: Use Inheritance to Eliminate Duplicate Declarations
- Tip #7: Use CSS Shorthand
- Use shorthand colors
- Shorthand properties
- Code: Shorthand property syntax
- Property value replication
- The margin shorthand property
- The border shorthand property
- The font shorthand property
- The background shorthand property
- The list-style shorthand property
- The outline shorthand property
- Tip #8: Abbreviate Long Class and ID Names
- Code: Abbreviate long names
- Using semantically meaningful names
- Comments in CSS
- Tip #9: Use CSS2 and CSS3.x Techniques
- Tip #10: Replace JavaScript Behavior with CSS Techniques
- Figure 7-1: How not to do a menu
- CSS buttons
- CSS rollovers
- Mono-image menu rollovers
- CSS sprites
- AOL.com CSS sprites
- Yahoo.com CSS Sprites
- List-based menus
- Figure 7-8. CableOrganizer.com CSS menus
- Conditional Comments to Avoid CSS Hacks (sidebar)
- Auto-expanding menus
- The body ID/class method
- Summary
- Build on a CSS Architecture