-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposition-area-explorer.html
More file actions
143 lines (132 loc) · 3.16 KB
/
position-area-explorer.html
File metadata and controls
143 lines (132 loc) · 3.16 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!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>position-area の値を試す</title>
<style>
*, *::before, *::after {
box-sizing: border-box;
}
body {
/* 画面中央に配置 */
display: grid;
place-items: center;
margin: 0;
font-family: sans-serif;
min-height: 100dvh;
background-color: #f5f5f5;
}
.anchor {
anchor-name: --my-anchor;
padding: 12px 20px;
background-color: #1a73e8;
color: #fff;
border: none;
border-radius: 4px;
font-size: 1rem;
cursor: pointer;
}
.tooltip {
position: absolute;
position-anchor: --my-anchor;
position-area: bottom center;
margin: 8px;
padding: 8px 12px;
background-color: #333;
color: #fff;
border-radius: 4px;
white-space: nowrap;
font-family: monospace;
font-size: 14px;
}
.controls {
position: fixed;
top: 0;
left: 0;
right: 0;
padding: 12px 16px;
background-color: #fff;
border-bottom: 1px solid #e0e0e0;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
}
.controls label {
font-size: 14px;
font-family: monospace;
}
.controls select {
padding: 6px 8px;
border-radius: 4px;
border: 1px solid #ccc;
font-size: 14px;
font-family: monospace;
}
</style>
</head>
<body>
<button class="anchor" type="button">アンカー要素</button>
<div class="tooltip" id="tooltip">bottom center</div>
<div class="controls">
<label for="select">position-area:</label>
<select id="select"></select>
</div>
<script>
const select = document.getElementById('select');
const tooltip = document.getElementById('tooltip');
const groups = [
['top', [
'top left',
'top center',
'top right',
'top',
'top span-all',
]],
['bottom', [
'bottom left',
'bottom center',
'bottom right',
'bottom',
'bottom span-all',
]],
['left', [
'left top',
'left center',
'left bottom',
'left',
'left span-all',
]],
['right', [
'right top',
'right center',
'right bottom',
'right',
'right span-all',
]],
['center', [
'center',
'span-all',
]],
];
groups.forEach(([label, values]) => {
const group = document.createElement('optgroup');
group.label = label;
values.forEach((value) => {
const option = document.createElement('option');
option.value = value;
option.textContent = value;
if (value === 'bottom center') option.selected = true;
group.appendChild(option);
});
select.appendChild(group);
});
select.addEventListener('change', () => {
tooltip.style.setProperty('position-area', select.value);
tooltip.textContent = select.value;
});
</script>
</body>
</html>