Welcome back to CodeYourCraft! Today, we're diving into the world of CSS Pseudo-classes. These magical tools can help you create engaging and interactive web pages. By the end of this tutorial, you'll be able to apply them like a pro! 💡
Pseudo-classes are special selectors in CSS that allow you to style elements based on their state or user interaction. Unlike normal selectors, they don't change the HTML structure but rather alter the presentation of the elements.
Pseudo-classes are essential for creating dynamic and interactive user interfaces. They help you style links on hover, activate buttons on click, and highlight form elements with errors, among other things.
Let's start with the most common pseudo-classes:
Applies to unvisited links.
a:link {
color: blue;
}Applies to links that have already been visited.
a:visited {
color: purple;
}Applies when the user hovers over a link.
a:hover {
color: red;
}Applies when a link is being clicked.
a:active {
color: green;
}Applies when an element has focus (usually through keyboard navigation).
input:focus {
box-shadow: 0 0 5px rgba(0, 0, 255, 0.5);
}Applies when an element is disabled.
input:disabled {
background-color: #f5f5f5;
cursor: not-allowed;
}Applies when a checkbox or radio button is selected.
<input type="checkbox" id="myCheck" />
<label for="myCheck"> Check me! </label>#myCheck:checked + label {
text-decoration: line-through;
}Which pseudo-class applies when a user clicks a link?
Stay tuned for the next part, where we'll dive even deeper into CSS Pseudo-classes! 📝