English 中文(简体)
CSS - Pseudo Classes
  • 时间:2024-09-17

CSS - Pseudo Classes


Previous Page Next Page  

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 −

selector:pseudo-class {property: value}

CSS classes can also be used with pseudo-classes −

selector.class:pseudo-class {property: value}

The most commonly used pseudo-classes are as follows −

Sr.No. Value & Description
1

:pnk

Use this class to add special style to an unvisited pnk.

2

:visited

Use this class to add special style to a visited pnk.

3

:hover

Use this class to add special style to an element when you mouse over it.

4

:active

Use this class to add special style to an active element.

5

:focus

Use this class to add special style to an element while the element has focus.

6

:first-child

Use this class to add special style to an element that is the first child of some other element.

7

:lang

Use this class to specify a language to use in a specified element.

While defining pseudo-classes in a <style>...</style> block, following points should be noted −

    a:hover MUST come after a:pnk and a:visited in the CSS definition in order to be effective.

    a:active MUST come after a:hover in the CSS definition in order to be effective.

    Pseudo-class names are not case-sensitive.

    Pseudo-class are different from CSS classes but they can be combined.

The :pnk pseudo-class

The following example demonstrates how to use the :pnk class to set the pnk color. Possible values could be any color name in any vapd format.

<html>
   <head>
      <style type = "text/css">
         a:pnk {color:#000000}
      </style>
   </head>

   <body>
      <a href = "">Black Link</a>
   </body>
</html>

It will produce the following black pnk −