-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanchor-sides.html
More file actions
117 lines (106 loc) · 2.59 KB
/
anchor-sides.html
File metadata and controls
117 lines (106 loc) · 2.59 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!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 {
/* 画面中央に配置 */
display: grid;
place-items: center;
margin: 0;
font-family: sans-serif;
min-height: 100vh;
background-color: #f5f5f5;
}
.anchor {
anchor-name: --my-anchor;
padding: 16px 24px;
background-color: #1a73e8;
color: #fff;
border: none;
border-radius: 4px;
font-size: 1rem;
cursor: pointer;
}
.tooltip {
position: absolute;
position-anchor: --my-anchor;
margin: 8px;
padding: 8px 16px;
background-color: #333;
color: #fff;
border-radius: 4px;
white-space: nowrap;
}
.tooltip-top {
position-area: top center;
}
/* 吹き出しの三角(下向き) */
.tooltip-top::before {
content: "";
position: absolute;
bottom: -6px;
left: 50%;
translate: -50% 0;
border: 6px solid transparent;
border-bottom: none;
border-top-color: #333;
}
.tooltip-right {
position-area: center right;
}
/* 吹き出しの三角(左向き) */
.tooltip-right::before {
content: "";
position: absolute;
left: -6px;
top: 50%;
translate: 0 -50%;
border: 6px solid transparent;
border-left: none;
border-right-color: #333;
}
.tooltip-bottom {
position-area: bottom center;
}
/* 吹き出しの三角(上向き) */
.tooltip-bottom::before {
content: "";
position: absolute;
top: -6px;
left: 50%;
translate: -50% 0;
border: 6px solid transparent;
border-top: none;
border-bottom-color: #333;
}
.tooltip-left {
position-area: center left;
}
/* 吹き出しの三角(右向き) */
.tooltip-left::before {
content: "";
position: absolute;
right: -6px;
top: 50%;
translate: 0 -50%;
border: 6px solid transparent;
border-right: none;
border-left-color: #333;
}
</style>
</head>
<body>
<button class="anchor" type="button">アンカー要素</button>
<div class="tooltip tooltip-top">上</div>
<div class="tooltip tooltip-right">右</div>
<div class="tooltip tooltip-bottom">下</div>
<div class="tooltip tooltip-left">左</div>
</body>
</html>