File tree Expand file tree Collapse file tree 3 files changed +85
-0
lines changed Expand file tree Collapse file tree 3 files changed +85
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments