Course Content
CSS Basic
0/1
CSS Selectors
0/1
CSS Comments
0/1
CSS Backgrounds
0/1
CSS Borders
0/1
CSS Outline
0/1
CSS Fonts
0/1
CSS Height and Width
0/1
CSS Margins and Paddings
0/2
CSS Icons
0/1
CSS Links
0/1
CSS Lists
0/1
CSS Tables
0/1
CSS Display Properties
0/1
CSS Max-Width Property
0/1
CSS Positioning Elements
0/1
CSS Z-Index Property
0/1
CSS Overflow
0/1
CSS Float
0/1
CSS Opacity
0/1
CSS Forms
0/1
CSS Dropdowns
0/1
CSS Buttons
0/1
CSS Media Queries
0/1
About Lesson

A pseudo-class in CSS is a keyword added to a selector that specifies a special state of the selected element(s). Pseudo-classes are used to style elements based on user interaction, element state, or other criteria. Here are some common pseudo-classes in CSS along with examples:

Applies styles when an element is being hovered over by the mouse cursor.

Example:

HTML
<button class="btn">Hover over me</button>
CSS
.btn:hover {
    background-color: blue;
    color: white;
}

Applies styles when an element is being activated, such as when a button is clicked.

Example:

HTML
<button class="btn">Click me</button>
CSS
.btn:active {
    background-color: red;
    color: white;
}

Applies styles when an element has focus, such as when an input field is selected.

Example:

HTML
<input type="text" class="input">
CSS
.input:focus {
    border-color: green;
}

Selects the first child element of its parent.

Example:

HTML
<ul>
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
</ul>
CSS
li:first-child {
    color: blue;
}

Selects elements based on their position within their parent.

HTML
<ul>
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
</ul>
CSS
li:nth-child(odd) {
    background-color: lightgray;
}