EN
CSS - text color change on hover
0 points
In this article, we would like to show you how to change text color on hover using CSS.
Quick solution:
xxxxxxxxxx
1
div:hover {
2
color: red;
3
}
In this example, we use CSS :hover
pseudo class to create a separate style for div
that is hovered. In order to change the text color, we use CSS color
property.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
div:hover {
7
color: red;
8
}
9
10
</style>
11
</head>
12
<body>
13
<div>Hover me to change the color</div>
14
</body>
15
</html>
In this example, we present a practical example of how to use the :hover
with class selectors. In order to change the text color, we use color
CSS property.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
.my-element:hover {
7
color: green;
8
}
9
10
</style>
11
</head>
12
<body>
13
<div class="my-element">Hover me to change the color</div>
14
</body>
15
</html>