Skip to content

Commit 43c1e48

Browse files
authored
Merge pull request you-dont-need#758 from rohitmane01/add-tooltip-demo
feat: add CSS-only Tooltip demo with delay and fade-in effect + Demo video
2 parents 07a5092 + 19a587b commit 43c1e48

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed
880 KB
Binary file not shown.

ToolTip with Delay/tooltip.css

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* Reset */
2+
body {
3+
font-family: sans-serif;
4+
display: flex;
5+
justify-content: center;
6+
align-items: center;
7+
height: 100vh;
8+
background: #fafafa;
9+
}
10+
11+
.tooltip-container {
12+
position: relative;
13+
display: inline-block;
14+
}
15+
16+
/* Target element */
17+
.tooltip-target {
18+
padding: 10px 20px;
19+
border: none;
20+
background: #0077cc;
21+
color: white;
22+
border-radius: 5px;
23+
cursor: pointer;
24+
}
25+
26+
/* Tooltip text */
27+
.tooltip-text {
28+
visibility: hidden;
29+
opacity: 0;
30+
width: max-content;
31+
background: #333;
32+
color: #fff;
33+
text-align: center;
34+
padding: 6px 12px;
35+
border-radius: 4px;
36+
37+
position: absolute;
38+
bottom: 125%; /* above the button */
39+
left: 50%;
40+
transform: translateX(-50%);
41+
42+
white-space: nowrap;
43+
pointer-events: none;
44+
45+
/* Animation */
46+
transition: opacity 0.3s ease;
47+
transition-delay: 0s; /* will be updated on hover */
48+
}
49+
50+
/* Tooltip arrow */
51+
.tooltip-text::after {
52+
content: "";
53+
position: absolute;
54+
top: 100%;
55+
left: 50%;
56+
margin-left: -5px;
57+
border-width: 5px;
58+
border-style: solid;
59+
border-color: #333 transparent transparent transparent;
60+
}
61+
62+
/* Show tooltip with delay */
63+
.tooltip-target:hover + .tooltip-text,
64+
.tooltip-target:focus + .tooltip-text {
65+
visibility: visible;
66+
opacity: 1;
67+
transition-delay: 0.5s; /* delay before showing */
68+
}

ToolTip with Delay/tooltip.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>CSS-only Tooltip with Delay</title>
7+
<link rel="stylesheet" href="tooltip.css">
8+
</head>
9+
<body>
10+
11+
<div class="tooltip-container">
12+
<button class="tooltip-target">Hover me</button>
13+
<span class="tooltip-text">I am a tooltip with a delay!</span>
14+
</div>
15+
16+
</body>
17+
</html>

0 commit comments

Comments
 (0)