-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanchor-multiple.html
More file actions
64 lines (60 loc) · 1.53 KB
/
anchor-multiple.html
File metadata and controls
64 lines (60 loc) · 1.53 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
<!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;
background-color: #f5f5f5;
position: relative;
}
.anchor-a {
anchor-name: --anchor-a;
position: absolute;
top: 50px;
left: 50px;
padding: 8px 16px;
background-color: #1a73e8;
color: #fff;
border-radius: 4px;
}
.anchor-b {
anchor-name: --anchor-b;
position: absolute;
top: 200px;
right: 100px;
padding: 8px 16px;
background-color: #e8711a;
color: #fff;
border-radius: 4px;
}
.positioned {
position: absolute;
/* position-anchor は指定しない。anchor() の引数でアンカー名を直接指定する */
top: anchor(--anchor-a bottom);
left: anchor(--anchor-a right);
bottom: anchor(--anchor-b top);
right: anchor(--anchor-b left);
margin: 8px;
background-color: rgba(26, 115, 232, 0.1);
border: 2px dashed #1a73e8;
display: flex;
align-items: center;
justify-content: center;
}
</style>
</head>
<body>
<div class="anchor-a">アンカーA</div>
<div class="anchor-b">アンカーB</div>
<div class="positioned">AとBの間</div>
</body>
</html>