-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtooltip.css
More file actions
62 lines (57 loc) · 1.69 KB
/
Copy pathtooltip.css
File metadata and controls
62 lines (57 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* Tooltip trigger container */
.tooltip {
--tooltip-text-color: #fff;
--tooltip-bg-color: #333;
position: relative;
cursor: pointer;
}
/* Create tooltip box and arrow using ::after and ::before pseudo-elements */
.tooltip::after,
.tooltip::before {
/* Position: centered above the parent element */
position: absolute;
bottom: 100%;
left: 50%;
transform: translateX(-50%);
/* Initially hidden */
opacity: 0;
visibility: hidden;
/* Smooth transition animation */
transition: opacity 0.4s ease;
/* Prevent being obscured by other elements */
z-index: 1000;
/* Use relative units for font-size to scale with parent element */
font-size: 0.8em;
}
/* Tooltip box */
.tooltip::after {
/* Get text from HTML data-tooltip attribute */
content: attr(data-tooltip);
/* Adjust spacing to properly align with the arrow.
The arrow (::before) has a border-width of 0.4em, so its total height is 0.8em (2 × 0.4em).
Subtracting 0.1em (0.8em - 0.1em = 0.7em) creates optimal visual connection between
the tooltip box and arrow, preventing overlap while maintaining seamless appearance. */
margin-bottom: 0.7em;
padding: 0.8em;
border-radius: 2px;
background-color: var(--tooltip-bg-color);
color: var(--tooltip-text-color);
white-space: nowrap;
}
/* Tooltip arrow */
.tooltip::before {
content: "";
border: 0.4em solid transparent;
border-top-color: var(--tooltip-bg-color);
}
/* Show tooltip and arrow on hover */
.tooltip:hover::after,
.tooltip:hover::before {
opacity: 1;
visibility: visible;
}