CSSpsuedoclasses
CSSpsuedoclasses
CSS pseudo-classes are used to add special effects to some selectors. You
do not need to use JavaScript or any other script to use those effects. A
simple syntax of pseudo-classes is as follows −
Value Description
:hover Use this class to add special style to an element when you mouse over
it.
:focus Use this class to add special style to an element while the element has
focus.
:first- Use this class to add special style to an element that is the first child of
child some other element.
a:active MUST come after a:hover in the CSS definition in order to be effective.
Pseudo-class are different from CSS classes but they can be combined.
<html>
<head>
<style type="text/css">
a:link {color:#000000}
</style>
</head>
<body>
</body>
</html>
<html>
<head>
<style type="text/css">
</head>
<body>
</body>
</html>
This will produce following link. Once you will click this link, it will change its
color to green.
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
</body>
</html>
It will produce the following link. Now you bring your mouse over this link
and you will see that it changes its color to yellow.
<head>
<style type="text/css">
</style>
</head>
<body>
</body>
</html>
It will produce the following link. When a user clicks it, the color changes to
pink.
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
</body>
</html>
It will produce the following link. When this link gets focused, its color
changes to orange. The color changes back when it loses focus.
The :first-child pseudo-class
The :first-child pseudo-class matches a specified element that is the first
child of another element and adds special style to that element that is the
first child of some other element.
For example, to indent the first paragraph of all <div> elements, you could
use this definition −
<html>
<head>
<style type="text/css">
text-indent: 25px;
</style>
</head>
<body>
<div>
</div>
<div>
<h3>Heading</h3>
<p>The first paragraph inside the div. This paragraph will not be
effected.</p>
</div>
</body>
</html>
In a document that needs to address this difference, you can use the :lang
pseudo-class to change the quote marks appropriately. The following code
changes the <blockquote> tag appropriately for the language being used −
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
</html>
The :lang selectors will apply to all the elements in the document. However,
not all elements make use of the quotes property, so the effect will be
transparent for most elements.