CSS pseudo-classes are used to add special effects to HTML elements.
You can set effects to the following HTML elements:
when a user mouses over it.
when a user mouses gets focus.
when a user visit and unvisited links .
Syntax : Pseudo Classes (Events)
selector:pseudo-class {
property: value;
}
selector.class:pseudo-class {
property: value
}
You can set following properties to pseudo-classes −
:link - a normal, unvisited link.
:visited - a link the user has visited link.
:hover - a link when the user mouses a:hover - a link when the user mouses over it.
:active - a link on which the user is currently clicking.
:focus - used to add special style to an element while the element has focus.
:first-child - used to add special style to an element that is the first child of some other element.
:lang - Used to specify a language to use in a specified element.
Links can be displayed in different ways.Check how links are displayed to different events. CSS - Links Tutorial
Buttons can be displayed in different ways.Check how buttons are displayed to different events. CSS - Links Tutorial
Example :
<!DOCTYPE html>
<html>
<head>
<style>
p:first-child {
color: blue;
}
input:focus {
background-color: yellow;
color:red;
}
</style>
</head>
<body>
<p>Code Always.</p>
<p>Code Always To Become Best Programmer.</p>
<form action="/action_page.php" method="get">
First Name: <input type="text" name="fname"><br>
Password: <input type="password" name="pass"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
When the above code is compiled , it produces the following result.