CSS active
Created By: chatGPT
In CSS, the
:active
pseudo-class is used to select elements that are in the process of being activated by the user. This typically refers to elements that are being clicked on or touched. You can apply various styles to that state, such as changing the color, background, or size of the element.button:active {
background-color: blue;
color: white;
transform: scale(0.98);
}
To use the
:active
pseudo-class, you can add it to a CSS selector for elements like buttons or links. Here's a quick example of styling a button when it is clicked.button {
background-color: green;
color: white;
padding: 10px 20px;
border: none;
cursor: pointer;
}
button:active {
background-color: darkgreen;
box-shadow: 0 5px #666;
transform: translateY(4px);
}
The
:active
state is temporary, so the styles you apply will only be visible for the short duration of the click or touch. You can combine this with other pseudo-classes, such as :hover
to create a more interactive user experience. Here's an example combining :hover
and :active
.a {
color: blue;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
color: red;
}
When designing interactive components with the
:active
pseudo-class, it's essential to ensure good visibility and focus. This often enhances user experience by providing immediate feedback upon interaction.input[type='submit']:active {
background-color: orange;
border: 1px solid darkorange;
}