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/anchor-center-offset-change.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<title>CSS Anchor Positioning Test: Dynamically change the anchor-center position</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
#cb {
position: relative;
width: 200px;
height: 200px;
}
#anchor {
width: 100px;
height: 100px;
anchor-name: --anchor;
}
#anchored {
position: absolute;
width: 100px;
height: 100px;
position-anchor: --anchor;
align-self: anchor-center;
left: anchor(--unknown right, 0px);
}
</style>
<div id="cb">
<div id="anchor"></div>
<div id="anchored"></div>
</div>
<script>
test(() => {
assert_equals(anchored.offsetLeft, 0);
assert_equals(anchored.offsetTop, 0);
}, "Anchored initially have the same width as the anchor");
test(() => {
anchor.style.height = "200px";
assert_equals(anchored.offsetLeft, 0);
assert_equals(anchored.offsetTop, 50);
}, "Increase the height of the anchor to move the anchor-center offset");
</script>