Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

23. CSS - Pseudo-classes

Lesson 23 of 34 in the free CSS Customization: Zero to Hero notes on Siksha Sarovar, written by Rohit Jangra.

CSS Pseudo-classes

A pseudo-class is used to define a special state of an element. For example, it can be used to:

  • Style an element when a user mouses over it.
  • Style visited and unvisited links differently.
  • Style an element when it gets focus.

Syntax

selector:pseudo-class {
  property: value;
}

Common Pseudo-classes

  1. :link: Selects all unvisited links.
  2. :visited: Selects all visited links.
  3. :hover: Selects elements when mouse is over them.
  4. :active: Selects the active element.
  5. :focus: Selects the element that has focus (e.g., input field).
  6. :first-child: Selects every element that is the first child of its parent.
  7. :last-child: Selects every element that is the last child of its parent.
  8. :nth-child(n): Selects every element that is the nth child of its parent.

Example - Simple Tooltip Hover

div {
  display: none;
}
p:hover div {
  display: block;
}

The :first-child Pseudo-class

Matches a specified element that is the first child of another element.

p:first-child {
  color: blue;
}

Matches the first <p> element in all <div> elements:

div p:first-child {
  background-color: yellow;
}