Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Enhancing Styles with User Action Pseudo-Classes | Section
CSS Fundamentals for React Developers - 1768407374224

bookEnhancing Styles with User Action Pseudo-Classes

User action pseudo-classes allow you to style elements based on how users interact with them. They are commonly applied to <button> and <a> elements to provide feedback during interactions.

The syntax is as follows:

selector:pseudo-class {
  property: value;
}
  • selector can be any selector we considered in the previous chapters;
  • pseudo-class needs : before its declaration, and we do not add any space.
Note
Note

We will consider the most helpful state pseudo-classes (hover, focus, active and visited).

:hover

Triggers when a user points to an element with a mouse cursor. Great for creating interactive visual feedback.

index.html

index.html

styles.css

styles.css

copy

:focus

Activates when an element receives keyboard focus (usually via the Tab key). To ensure accessibility, hover and focus styles are often paired, giving mouse and keyboard users a consistent experience.

The difference between :hover and :focus

  • :hover reacts to mouse cursor activity;
  • :focus reacts to the keyboard activity ("Tab" key).

In the following example, we have the same element with different pseudo-classes. Please pay attention to the styles.css file. We can notice that we can add the same styles for the hover and focus effect by separating the selector and pseudo-class with ,.

index.html

index.html

styles.css

styles.css

copy

:active

Triggered while an element is being activated, commonly during a mouse click on buttons or links.

index.html

index.html

styles.css

styles.css

copy

:visited

Applies to links after the user has already visited their destination. Browsers typically display unvisited links in blue and visited ones in purple, unless you override these styles.

index.html

index.html

styles.css

styles.css

copy

1. Which pseudo-class is triggered when a user hovers their mouse over an element?

2. Which pseudo-class is applied to a link that has already been visited?

question mark

Which pseudo-class is triggered when a user hovers their mouse over an element?

Select the correct answer

question mark

Which pseudo-class is applied to a link that has already been visited?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 6

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

bookEnhancing Styles with User Action Pseudo-Classes

Свайпніть щоб показати меню

User action pseudo-classes allow you to style elements based on how users interact with them. They are commonly applied to <button> and <a> elements to provide feedback during interactions.

The syntax is as follows:

selector:pseudo-class {
  property: value;
}
  • selector can be any selector we considered in the previous chapters;
  • pseudo-class needs : before its declaration, and we do not add any space.
Note
Note

We will consider the most helpful state pseudo-classes (hover, focus, active and visited).

:hover

Triggers when a user points to an element with a mouse cursor. Great for creating interactive visual feedback.

index.html

index.html

styles.css

styles.css

copy

:focus

Activates when an element receives keyboard focus (usually via the Tab key). To ensure accessibility, hover and focus styles are often paired, giving mouse and keyboard users a consistent experience.

The difference between :hover and :focus

  • :hover reacts to mouse cursor activity;
  • :focus reacts to the keyboard activity ("Tab" key).

In the following example, we have the same element with different pseudo-classes. Please pay attention to the styles.css file. We can notice that we can add the same styles for the hover and focus effect by separating the selector and pseudo-class with ,.

index.html

index.html

styles.css

styles.css

copy

:active

Triggered while an element is being activated, commonly during a mouse click on buttons or links.

index.html

index.html

styles.css

styles.css

copy

:visited

Applies to links after the user has already visited their destination. Browsers typically display unvisited links in blue and visited ones in purple, unless you override these styles.

index.html

index.html

styles.css

styles.css

copy

1. Which pseudo-class is triggered when a user hovers their mouse over an element?

2. Which pseudo-class is applied to a link that has already been visited?

question mark

Which pseudo-class is triggered when a user hovers their mouse over an element?

Select the correct answer

question mark

Which pseudo-class is applied to a link that has already been visited?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 6
some-alt