Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 14 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /css/css-anchor-position/position-area-align-justify.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<title>CSS Anchor Positioning: position-area positioning - alignment</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
/* A 300x300 container with a 100x100 centered anchor */
#container {
position: relative;
width: 300px;
height: 300px;
}
#anchor {
position: absolute;
top: 100px;
left: 100px;
width: 100px;
height: 100px;
anchor-name: --anchor;
}
#anchored {
position: absolute;
width: 10px;
height: 10px;
inset: 10px;
position-anchor: --anchor;
}
</style>
<div id="container">
<div id="anchor"></div>
<div id="anchored"></div>
</div>
<script>
function test_position_area(position_area, expected_offsets) {
anchored.style.positionArea = position_area;
test(() => {
assert_equals(anchored.offsetLeft, expected_offsets.left, "Check expected offsetLeft");
assert_equals(anchored.offsetTop, expected_offsets.top, "Check expected offsetTop");
assert_equals(anchored.offsetWidth, expected_offsets.width, "Check expected offsetWidth");
assert_equals(anchored.offsetHeight, expected_offsets.height, "Check expected offsetHeight");
}, "Offsets for position-area: " + position_area);
}
// anchor-center in both directions
test_position_area("span-all", {left:145, top:145, width:10, height:10});
// Single region spans
test_position_area("top left", {left:80, top:80, width:10, height:10});
test_position_area("top center", {left:145, top:80, width:10, height:10});
test_position_area("top right", {left:210, top:80, width:10, height:10});
test_position_area("center left", {left:80, top:145, width:10, height:10});
test_position_area("center center", {left:145, top:145, width:10, height:10});
test_position_area("center right", {left:210, top:145, width:10, height:10});
test_position_area("bottom left", {left:80, top:210, width:10, height:10});
test_position_area("bottom center", {left:145, top:210, width:10, height:10});
test_position_area("bottom right", {left:210, top:210, width:10, height:10});
// Multi-region spans
test_position_area("top span-left", {left:180, top:80, width:10, height:10});
test_position_area("top span-right", {left:110, top:80, width:10, height:10});
test_position_area("span-top left", {left:80, top:180, width:10, height:10});
test_position_area("span-bottom left", {left:80, top:110, width:10, height:10});
</script>