Cascading Style Sheet (CSS) optimization transforms your HTML by abstracting inline style and behavior into minimal style sheets. Whereas CSS makes a site easier to maintain, CSS optimization makes it load faster and makes it more search-engine friendly.
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
- Tip #9: Use CSS2 and CSS3.x Techniques
- Tip #10: Replace JavaScript Behavior with CSS Techniques
- Summary
« Web Page Optimization |
CSS Optimization |
Ajax Optimization »