CSS Pseudo-Classes

CSS Pseudo-classes, List of CSS Pseudo-classes, Syntax of Pseudo-class, Impostant rules, Anchor Pseudo-classes

CSS pseudo-classes are used to define a special state of an element such as :hover, :active, :focus, :link, and :checked as well as CSS pseudo elements ::after, ::before, ::selection, etc.

Uses of CSS Pseudo-Classes

  • Add special style to visited and unvisited links and easy differentiate it.
  • Easily change the style of an element when you moving the mouse on an element.
  • Style an element when it gets focus.

Syntax of pseudo-classes

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

CSS Pseudo Classes

  • :active - The :active pseudo-class use to selects the active link
  • :link - The :link pseudo-class use to selects all unvisited links
  • :hover - The :hover pseudo-class use to add special style to an element when you mouse over it
  • :focus - The :focus pseudo-class use to add special style to an element while the element has focus
  • :checked - The :checked pseudo-class use to selects every checked elements
  • :disabled - The :disabled pseudo-class use to selects every disabled elements
  • :empty - The :empty pseudo-class use to selects every elements that has no children
  • :first-child - The :first-child pseudo-class use to selects every elements that is the first child of its parent
  • :valid - The :valid pseudo-class use to selects all elements with a valid value
  • :visited - The :visited pseudo-class use to selects all visited links

Important Rules of Pseudo-Classes

  • a:hover MUST come after a:link 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 can be combined with CSS classes.

The :active Pseudo Class

The actice pseudo-class is used to change the color of active links:

:active Pseudo Class Example

a :active {
     color: blue;
  }

Output


The :link Pseudo Class

The link pseudo-class is used to set the link color:

:link Pseudo Class Example

a :link {
     color: pink;
  }

Output

The :hover Pseudo Class

The hover pseudo-class is used to change the color of links when bring a mouse pointer over the link:

:hover Pseudo Class Example

a :hover {
     color: red;
  }

Output

Tooltip :hover

Tooltip hover is used to display the element when the mouse pointer over the link, paragraph OR element. Suppose that, you have a <div> element to show a <p> element:

Tooltip hover Example

p {
     color: #fff;
     background-color: green;
     padding: 10px;
     border: 1px dotted red;
  }
div :hover p {
     display: block;
  }

Related Topics

Jumpstart Your Real Estate Business with Effective Lead Generation

Shagufta Anurag Net Worth 2024, Business, Salary, Income Source, Car, House

Devanshi Kejriwal Net Worth 2024, Business, Salary, Income Source, Car, House

Average salary in South Sudan

What are the limitations of financial statements?

Bikash Dash Net Worth 2024, Business, Salary, Income Source, Car, House

Average salary in Finland

Saumya Singh Rathore Net Worth 2024, Business, Salary, Income Source, Car, House

Amit Bhasin Net Worth 2024, Business, Salary, Income Source, Car, House

Nita Ambani Net Worth 2024, Business, Salary, Income Source, Car, House

Pulkit Agrawal Net Worth 2024, Business, Salary, Income Source, Car, House

What are the features of Indian Economy?

Average salary in Iceland

How to Find a Sponsor for Your Series 7 Examination

Average salary in Chad

Where to invest money for the long term?

Business Operations

What are the approaches used to measure the National Income?

Anant Goel Net Worth 2024, Business, Salary, Income Source, Car, House

Abhishek Bansal Net Worth 2024, Business, Salary, Income Source, Car, House

Shan Kadavil Net Worth 2024, Business, Salary, Income Source, Car, House

Nithin Kamath Net Worth 2024, Business, Salary, Income Source, Car, House

Average salary in Taiwan

Empowering Individuals: How Helping Businesses Make Better Decisions Can Earn You Extra Money

Average salary in Namibia

Ashish Goel Net Worth 2024, Business, Salary, Income Source, Car, House

Bhuvan Gupta Net Worth 2024, Business, Salary, Income Source, Car, House

Akshay Khanna Net Worth 2024, Business, Salary, Income Source, Car, House

Average salary in Nicaragua

Zishaan Hayath Net Worth 2024, Business, Salary, Income Source, Car, House

Email Us: advertise@gdatamart.com

Donate Us: Support to GDATAMART

© 2023 GDATAMART.COM (All Rights Reserved)