Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 2 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /css/css-anchor-position/position-area-pseudo-element-implicit-anchor.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<title>Implicit anchor element for pseudo-elements using anchor functions</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
body { margin: 0 }
#target {
margin-top: 100px;
margin-left: 50px;
width: 100px;
height: 100px;
background: blue;
}
#target::before, #target::after {
width: 100px;
height: 100px;
position: absolute;
}
#target.moved {
margin-top: 200px;
margin-left: 200px;
}
#target::before {
position-area: center right;
background: green;
content:'';
}
#target::after {
position-area: bottom center;
background: green;
content:'';
}
</style>
<div id=target></div>
<script>
test(() => {
assert_equals(getComputedStyle(target, '::before').top, '100px');
assert_equals(getComputedStyle(target, '::before').left, '150px');
assert_equals(getComputedStyle(target, '::after').top, '200px');
assert_equals(getComputedStyle(target, '::after').left, '50px');
}, "The implicit anchor element of a pseudo-element is its originating element");
test(() => {
target.classList.add("moved");
assert_equals(getComputedStyle(target, '::before').top, '200px');
assert_equals(getComputedStyle(target, '::before').left, '300px');
assert_equals(getComputedStyle(target, '::after').top, '300px');
assert_equals(getComputedStyle(target, '::after').left, '200px');
}, "Anchored position after moving");
</script>