WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

CSS Pseudo-classes


What are Pseudo-classes?

The CSS pseudo-classes enable us to style components, or parts of components, that exist in the archive tree without utilizing JavaScript or some other scripts


Syntax

The grammar of pseudo-classes:

selector:pseudo-class {
    property:value;
}

Anchor Pseudo-classes

Links can be shown in various ways:

Example

/* unvisited interface */
a:link {
    shading: hotpink;
}

/* visited connect */
a:visited {
    shading: green;
}

/* mouse over connection */
a:hover {
    color:yellow;
}

/* chose connection */
a:active {
    shading: red;
}
Try it yourself »

Pseudo-classes and CSS Classes

Pseudo-classes can be joined with CSS classes:

When you drift over the connection in the precedent, it will change color:

Example

a.highlight:hover {
    shading: hotpink;
}
Try it yourself »

Hover on <div>

An case of utilizing the :hover pseudo-class on a <div> element:

Example

div:hover {
    foundation shading: blue;
}
Try it yourself »

CSS - The :principal tyke Pseudo-class

The :first-child pseudo-class coordinates a predefined component that is the main offspring of another element.

Match the first <p> element

In the accompanying precedent, the selector coordinates any <p> component that is the principal offspring of any element:

Example

p:first-tyke {
    shading: blue;
}
Try it yourself »

Match the first <i> component in all <p> elements

In the accompanying precedent, the selector coordinates the first <i> component in all <p> elements:

Example

p i:first-youngster {
    shading: blue;
}
Try it yourself »

Match all <i> components in all first youngster <p> elements

In the accompanying model, the selector coordinates all <i> components in <p> components that are the main offspring of another element:

Example

p:first-kid I {
    shading: blue;
}
Try it yourself »

CSS - The :lang Pseudo-class

The :lang pseudo-class enables you to characterize exceptional guidelines for various languages.

In the model beneath, :lang characterizes the quotes for <q> components with lang="no":

Example

<html>
<head>
<style>
q:lang(no) {
    cites: "~" "~";

}
</style>
</head>

<body>
<p>Some content <q lang="no">A quote in a paragraph</q> Some text.</p>
</body>
</html>
Try it yourself »