Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

Pseudo-classes

You’ve surely noticed that some elements change when you move the mouse pointer over them: a button gets darker, a link changes color. This is done with pseudo-classes.

A pseudo-class selects elements in a certain state. It starts with a colon and is usually written right after another selector. The pseudo-class :hover selects an element while the mouse pointer is over it:

li:hover {
	color: purple;
}

With this rule, a list item turns purple when you point at it, and gets its color back when you move the pointer away. You can add :hover to any selector, for example h2:hover or #breeds:hover.

Keep in mind that phones and tablets have no mouse pointer, so nothing important should be visible only on hover.

Instructions

  1. 1

    Create a rule for a:hover that sets a yellow background: background-color: yellow. Then move the mouse pointer over the links in the footer.

Back

9/17

  1. 1. Rules and Comments
  2. 2. Quiz: Rules
  3. 3. Universal Selector
  4. 4. Type Selector
  5. 5. Class Selector
  6. 6. ID Selector
  7. 7. Quiz: Class or ID?
  8. 8. Attribute Selector
  9. 9. Pseudo-classes
  10. 10. Grouping Selectors
  11. 11. Chaining Selectors
  12. 12. Selecting Descendants
  13. 13. Selecting Children
  14. 14. The Cascade
  15. 15. Specificity
  16. 16. Inheritance
  17. 17. Summary
Next

Try it yourself

Do this exercise right here in your browser. No account needed.