-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathanchor-function-pseudo-element-basic.html
More file actions
55 lines (54 loc) · 1.94 KB
/
anchor-function-pseudo-element-basic.html
File metadata and controls
55 lines (54 loc) · 1.94 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
<!DOCTYPE html>
<title>Positioning pseudo-elements using anchor functions</title>
<link rel="help" href="https://drafts.csswg.org/css-anchor-position-1/#positioning">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
body { margin: 0 }
#anchor, #target::before, #target::after {
width: 100px;
height: 100px;
position: absolute;
}
#anchor.moved {
left: 200px;
top: 200px;
}
#anchor {
left: 50px;
top: 100px;
anchor-name: --a;
background: blue;
}
#target::before {
position-anchor: --a;
left: anchor(right);
top: anchor(top);
background: green;
content:'';
}
#target::after {
position-anchor: --a;
left: anchor(left);
top: anchor(bottom);
background: green;
content:'';
}
</style>
<div id=anchor></div>
<div id=target></div>
<script>
test(() => {
assert_equals(getComputedStyle(target, '::before').top, '100px', "#target::before top is positioned against anchor");
assert_equals(getComputedStyle(target, '::before').left, '150px', "#target::before left is positioned against anchor");
assert_equals(getComputedStyle(target, '::after').top, '200px', "#target::after top is positioned against anchor");
assert_equals(getComputedStyle(target, '::after').left, '50px', "#target::after left is positioned against anchor");
}, "Initial anchored position");
test(() => {
anchor.classList.add("moved");
assert_equals(getComputedStyle(target, '::before').top, '200px', "#target::before top is positioned against anchor");
assert_equals(getComputedStyle(target, '::before').left, '300px', "#target::before left is positioned against anchor");
assert_equals(getComputedStyle(target, '::after').top, '300px', "#target::after top is positioned against anchor");
assert_equals(getComputedStyle(target, '::after').left, '200px', "#target::after left is positioned against anchor");
}, "Anchored position after moving");
</script>