Attribute Selectors: Free HTML & CSS Tutorial
Master CSS Attribute Selectors for Dynamic Link Styling
Core CSS Selectors Covered
Ends With Selector
Target attributes ending with specific values using $= syntax. Perfect for file extensions like .pdf or .jpg.
Begins With Selector
Target attributes starting with specific values using ^= syntax. Ideal for external links starting with http.
Contains Selector
Target attributes containing specific strings using *= syntax. Great for domain-specific targeting like youtube.com.
Link Types in This Tutorial
Setup Requirements
Prevents confusion when switching between projects
Located in Desktop > Class Files > Advanced HTML CSS Class
Establishes baseline view before adding enhancements
Verify PDF, YouTube, and external website functionality
Icon Implementation Process
Add Background Image
Apply initial PDF icon using url(../img/icon-pdf.png) to all anchor tags
Stop Image Repetition
Add no-repeat property to prevent icon from tiling across the background
Position the Icon
Use right center positioning to place icon on the right side of each link
Set Icon Size
Define 16px dimensions using background-size property for consistent appearance
Add Padding Space
Apply 24px right padding to create visual space between text and icon
All icons are designed at exactly 16px by 16px to maintain visual consistency across different link types. The 24px padding provides 8px of breathing room around each icon.
Selector Specificity Comparison
| Feature | Method | Reusability | Maintenance |
|---|---|---|---|
| Exact Match | Single link only | Poor | |
| Ends With (.pdf) | All PDF files | Excellent | |
| Class-based | Manual addition needed | Medium |
Key Takeaways
