last-successful-pseudo-element-fallbacks.html (2252B)
1 <!DOCTYPE html> 2 3 <title>CSS Anchor Positioning: changing position-try-fallbacks invalidates last successful position fallback on pseudo-elements</title> 4 <link rel="author" title="Kiet Ho" href="mailto:kiet.ho@apple.com"> 5 6 <link rel="help" href="https://drafts.csswg.org/css-anchor-position/#last-successful-position-fallback"> 7 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <script src="support/test-common.js"></script> 11 12 <style> 13 #container { 14 position: relative; 15 width: 400px; 16 height: 400px; 17 background: teal; 18 } 19 #anchor { 20 position: relative; 21 top: 100px; 22 left: 100px; 23 width: 100px; 24 height: 100px; 25 background: red; 26 anchor-name: --a; 27 } 28 #anchored::before { 29 position-anchor: --a; 30 bottom: anchor(top); 31 left: anchor(left); 32 position-try-fallbacks: flip-block; 33 position: absolute; 34 width: 100px; 35 height: 200px; 36 background: lime; 37 content: ""; 38 } 39 /* 40 Hack to change position-try-fallbacks of the pseudo-element, 41 since there's no easy way to change it in JavaScript. 42 */ 43 #anchored.new-fallback::before { 44 position-try-fallbacks: flip-block, --foo; 45 } 46 </style> 47 48 <div id="container"> 49 <div id="anchor"></div> 50 <div id="anchored"></div> 51 </div> 52 <script> 53 promise_test(async () => { 54 await waitUntilNextAnimationFrame(); 55 await waitUntilNextAnimationFrame(); 56 const anchoredStyle = getComputedStyle(anchored, "::before"); 57 assert_equals(anchoredStyle.top, "200px"); 58 }, "Starts rendering with flip-block"); 59 60 promise_test(async () => { 61 anchor.style.top = "150px"; 62 await waitUntilNextAnimationFrame(); 63 await waitUntilNextAnimationFrame(); 64 const anchoredStyle = getComputedStyle(anchored, "::before"); 65 assert_equals(anchoredStyle.top, "250px"); 66 }, "No successful position, keep flip-block"); 67 68 promise_test(async () => { 69 anchored.classList.add("new-fallback"); 70 await waitUntilNextAnimationFrame(); 71 await waitUntilNextAnimationFrame(); 72 const anchoredStyle = getComputedStyle(anchored, "::before"); 73 assert_equals(anchoredStyle.top, "-50px"); 74 }, "No successful position, last successful invalidated by position-try-fallbacks change"); 75 </script>