CSS PSEUDO-CLASS

rainbow baker

 CSS PSEUDO-CLASS

  • A Pseudo class in CSS is used to define the special state of an element
  • It can be combined with a CSS selector to add an effect to existing elements based on their states.
  • changing the style of an element when the user hovers over it, or when a link is visited.
  • All of these can be done using Pseudo Classes in CSS.

SYNTAX:

selector: pseudo-class
{
property:values;
}

EXAMPLE

<!DOCTYPE html>
<html>
<head>
<style>
/* unvisited link */
a:link {
  color: red;
}
/* visited link */
a:visited {
  color: green;
}
/* mouse over link */
a:hover {
  color: hotpink;
}
/* selected link */
a:active {
  color: blue;
}
</style>
</head>
<body>
<h2>Styling a link depending on state</h2>
<p><b><a href="default.asp" target="_blank">This is a link</a></b></p>
<p><b>Note:</b> a:hover MUST come after a:link and a:visited in the CSS definition in order to be effective.</p>
<p><b>Note:</b> a:active MUST come after a:hover in the CSS definition in order to be effective.</p>
</body>
</html>

OUTPUT



Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send