EN
CSS - show text on hover
3 points
In this article, we would like to show you how to show text on hover using CSS.
Simple steps:
- create two elements:
div.container
anddiv.text
(insidediv.container
), - set
div.text
element as invisible by default usingdisplay: none
property, - add
:hover
pseudo-class fordiv.container
element definingdisplay: block
property ondiv.text
.
Practical example:
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
body {
7
height: 50px;
8
}
9
10
div.container {
11
padding: 5px;
12
border-radius: 5px;
13
background: #28a745;
14
width: 70px;
15
height: 15px;
16
color: white;
17
}
18
19
.text {
20
padding: 5px;
21
position: relative;
22
left: 75px;
23
top: 5px;
24
background: #bebebe;
25
width: 100px;
26
height: 15px;
27
color: black;
28
display: none; /* <----- hides text by default */
29
}
30
31
div.container:hover .text {
32
display: block; /* <----- shows text on hover */
33
}
34
35
</style>
36
</head>
37
<body>
38
<div class="container">
39
Hover me!
40
<div class="text">Example text...</div>
41
</div>
42
</body>
43
</html>