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/container-queries/anchored-fallback-scroll.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<title>CSS Conditional Test: @container anchored(fallback) changes on scroll</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/css-conditional/container-queries/support/cq-testcommon.js"></script>
<script src="/css/css-transitions/support/helper.js"></script>
<style>
body { margin: 0; }
#anchor {
anchor-name: --a;
margin-top: 100px;
width: 100px;
height: 100px;
}
#anchored {
position: absolute;
position-anchor: --a;
position-area: top;
position-try-fallbacks: flip-block;
width: 100px;
height: 100px;
container-type: anchored;
}
@container anchored(fallback: none) {
#t1 { --fallback: no; }
}
@container anchored(fallback: flip-block) {
#t1 { --fallback: yes; }
}
</style>
<div id="anchor"></div>
<div id="anchored">
<div id="t1"></div>
</div>
<div style="height:3000px">XXX</div>
<script>
promise_test(async t => {
await waitForAnimationFrames(2);
assert_equals(anchored.offsetTop, 0);
assert_equals(document.documentElement.scrollTop, 0);
assert_equals(getComputedStyle(t1).getPropertyValue("--fallback"), "no");
}, "@container anchored() without applied fallback at initial scroll position");
promise_test(async t => {
document.documentElement.scrollTop = 100;
await waitForAnimationFrames(2);
assert_equals(anchored.offsetTop, 200);
assert_equals(getComputedStyle(t1).getPropertyValue("--fallback"), "yes");
}, "@container anchored() applies fallback after scrolling down");
</script>