scroll-state-snapped-pseudo.html (1878B)
1 <!DOCTYPE html> 2 <title>@container: scroll-state(snapped) layout change</title> 3 <link rel="help" href="https://drafts.csswg.org/css-conditional-5/#snapped"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/css/css-conditional/container-queries/support/cq-testcommon.js"></script> 7 <script src="/css/css-transitions/support/helper.js"></script> 8 <style> 9 :root { 10 scroll-snap-type: block proximity; 11 } 12 body { 13 margin: 0; 14 } 15 #filler-before { 16 height: 10px; 17 } 18 #filler-after { 19 height: 10000px; 20 } 21 #snapped { 22 position: relative; 23 top: 3000px; /* Should be enough to not snap for proximity */ 24 container-type: scroll-state inline-size; 25 scroll-snap-align: start; 26 --before: no; 27 --after: no; 28 @container scroll-state(snapped) { 29 &::before { 30 --before: yes; 31 content: " "; 32 } 33 &::after { 34 --after: yes; 35 } 36 } 37 } 38 </style> 39 <div id="filler-before"></div> 40 <div id="snapped"></div> 41 <div id="filler-after"></div> 42 <script> 43 setup(() => { 44 assert_implements_scroll_state_container_queries(); 45 assert_implements_size_container_queries(); 46 }); 47 48 promise_test(async t => { 49 await waitForAnimationFrames(2); 50 assert_equals(getComputedStyle(snapped, "::before").getPropertyValue("--before"), "no"); 51 assert_equals(getComputedStyle(snapped, "::after").getPropertyValue("--after"), "no"); 52 }, "Initially, snapped query does not match and ::before/::after do not apply"); 53 54 promise_test(async t => { 55 snapped.style.top = "auto"; 56 await waitForAnimationFrames(2); 57 assert_equals(getComputedStyle(snapped, "::before").getPropertyValue("--before"), "yes"); 58 assert_equals(getComputedStyle(snapped, "::after").getPropertyValue("--after"), "yes"); 59 }, "::before/::after depending on snapped query"); 60 61 </script>