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-basic.html - WPT Dashboard Interop Dashboard
 
 
<!DOCTYPE html>
<title>CSS Conditional Test: Basic @container anchored(fallback) support</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>
<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;
  }
  .anchored + .anchored {
    /* Too tall to fit over the anchor to trigger fallback */
    height: 200px;
  }
  @container anchored(fallback: none) {
    div { --fallback: no; }
  }
  @container anchored(fallback: flip-block) {
    div { --fallback: yes; }
  }
</style>
<div id="anchor"></div>
<div class="anchored">
  <div id="t1"></div>
</div>
<div class="anchored">
  <div id="t2"></div>
</div>
<script>
  test(() => {
    assert_equals(document.querySelector(".anchored").offsetTop, 0);
    assert_equals(getComputedStyle(t1).getPropertyValue("--fallback"), "no");
  }, "@container anchored() without applied fallback");
  test(() => {
    assert_equals(document.querySelector(".anchored + .anchored").offsetTop, 200);
    assert_equals(getComputedStyle(t2).getPropertyValue("--fallback"), "yes");
  }, "@container anchored() with fallback applied");
</script>