-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanchor-basic.html
More file actions
62 lines (58 loc) · 1.42 KB
/
anchor-basic.html
File metadata and controls
62 lines (58 loc) · 1.42 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
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>ボタンの下にツールチップを表示する</title>
<style>
*, *::before, *::after {
box-sizing: border-box;
}
body {
margin: 0;
font-family: sans-serif;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background-color: #f5f5f5;
}
.anchor {
anchor-name: --my-anchor;
width: fit-content;
padding: 8px 16px;
background-color: #1a73e8;
color: #fff;
border-radius: 4px;
}
.tooltip {
position: absolute;
position-anchor: --my-anchor;
top: calc(anchor(bottom) + 8px);
left: anchor(center);
translate: -50% 0;
padding: 8px 16px;
background-color: #333;
color: #fff;
border-radius: 4px;
white-space: nowrap;
}
/* 吹き出しの三角(上向き) */
.tooltip::before {
content: "";
position: absolute;
top: -6px;
left: 50%;
translate: -50% 0;
border: 6px solid transparent;
border-top: none;
border-bottom-color: #333;
}
</style>
</head>
<body>
<div class="anchor">アンカー要素</div>
<div class="tooltip">ツールチップのテキストが入ります</div>
</body>
</html>