Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE html>
<title>CSS Anchor Positioning: basic last successful position fallback</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/test-common.js"></script>
<iframe id="iframe" srcdoc='
<style>
#container {
position: relative;
width: 400px;
height: 400px;
background: teal;
}
#anchor {
position: relative;
top: 100px;
left: 100px;
width: 100px;
height: 100px;
background: red;
anchor-name: --a;
}
#anchored {
position-anchor: --a;
position-try-fallbacks: flip-block;
position: absolute;
width: 100px;
height: 200px;
position-area: top center;
background: lime;
}
</style>
<div id="container">
<div id="anchor"></div>
<div id="anchored"></div>
</div>
'></iframe>
<script>
// Wait for the iframe to load:
onload = function() {
const doc = iframe.contentWindow.document;
const container = doc.getElementById('container');
const anchor = doc.getElementById('anchor');
const anchored = doc.getElementById('anchored');
promise_test(async () => {
await waitUntilNextAnimationFrame();
await waitUntilNextAnimationFrame();
assert_equals(anchored.offsetTop, 200);
}, "Starts rendering with flip-block");
promise_test(async () => {
anchor.style.top = "150px";
await waitUntilNextAnimationFrame();
await waitUntilNextAnimationFrame();
assert_equals(anchored.offsetTop, 250);
}, "No successful position, keep flip-block");
promise_test(async () => {
anchor.style.top = "200px";
await waitUntilNextAnimationFrame();
await waitUntilNextAnimationFrame();
assert_equals(anchored.offsetTop, 0);
}, "Base position without fallback now successful");
}
</script>