Skip to content

Buzzingz

Unleashing the Power of Code

  • HTML
  • CSS
  • Toggle search form

CSS Pseudo-classes

Posted on March 15, 2023March 15, 2023 By shani No Comments on CSS Pseudo-classes

CSS pseudo-classes are used to apply special styles to an element based on its state or position within the document tree. Here are some commonly used pseudo-classes:

  • :hover: This pseudo-class is used to apply styles to an element when the mouse cursor is hovering over it.
  • :active: This pseudo-class is used to apply styles to an element when it is being activated, such as when a user clicks on a link.
  • :focus: This pseudo-class is used to apply styles to an element that currently has focus, such as a text input field.
  • :first-child: This pseudo-class is used to apply styles to the first child element of a parent element.
  • :last-child: This pseudo-class is used to apply styles to the last child element of a parent element.
  • :nth-child(): This pseudo-class is used to apply styles to elements that match a specific pattern based on their position in the parent element.
  • :nth-of-type(): This pseudo-class is similar to :nth-child(), but it only applies to elements of a specific type.

Here are some examples of how these pseudo-classes can be used in CSS:

/* Styles for links when hovered over */
a:hover {
  color: red;
}

/* Styles for text inputs when in focus */
input[type="text"]:focus {
  border: 2px solid blue;
}

/* Styles for the first child element of a list */
ul li:first-child {
  font-weight: bold;
}

/* Styles for even-numbered rows of a table */
tr:nth-child(even) {
  background-color: lightgray;
}

/* Styles for odd-numbered paragraphs within a div */
div p:nth-of-type(odd) {
  font-style: italic;
}

By using these pseudo-classes, you can create more dynamic and interactive styles that respond to user actions and the structure of your HTML document.

CSS

Post navigation

Previous Post: CSS Combinators
Next Post: CSS Pseudo-elements

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

CSS Tutorial

  • Basic CSS Tutorial For Beginners
  • CSS Introduction
  • CSS Syntax
  • CSS Selectors
  • How To Add CSS
  • CSS Comments
  • CSS Colors
  • CSS Backgrounds
  • CSS Borders
  • CSS Margins
  • CSS Margin Collapse
  • CSS Padding
  • CSS Height, Width and Max-width
  • CSS Box Model
  • CSS Outline
  • CSS Text
  • CSS Fonts
  • CSS Web Safe Fonts
  • CSS Font Fallbacks
  • CSS Font Style
  • CSS Font Size
  • CSS Google Fonts
  • CSS Great Font Pairings
  • CSS Icons
  • CSS Links
  • CSS Lists
  • CSS Tables
  • CSS Layout – display: inline-block
  • CSS Layout – float and clear
  • CSS Layout – Horizontal & Vertical Align
  • CSS Layout – Overflow
  • CSS Layout – The display Property
  • CSS Layout – The z-index Property
  • CSS Layout – width and max-width
  • CSS Layout – The position Property
  • CSS Attribute Selectors
  • CSS Image Sprites
  • CSS Image Gallery
  • CSS Dropdowns
  • CSS Horizontal Navigation Bar
  • CSS Vertical Navigation Bar
  • CSS Navigation Bar
  • CSS Opacity / Transparency
  • CSS Pseudo-elements
  • CSS Pseudo-classes
  • CSS Combinators
  • CSS Math Functions
  • CSS The !important Rule
  • CSS Specificity
  • CSS Units
  • CSS Website Layout
  • CSS Counters
  • CSS Forms
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions

Copyright © 2023 Buzzingz.

Powered by PressBook WordPress theme