last-successful-pseudo-element-basic.html (2162B)
1 <!DOCTYPE html> 2 3 <title>CSS Anchor Positioning: basic 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 /* 31 We can't use position-area, since there's no way to access offsetTop of 32 pseudo-elements to check for position. Instead, we have to use anchor() 33 and check the computed inset values. 34 */ 35 bottom: anchor(top); 36 left: anchor(left); 37 position-try-fallbacks: flip-block; 38 position: absolute; 39 width: 100px; 40 height: 200px; 41 background: lime; 42 content: ""; 43 } 44 </style> 45 46 <div id="container"> 47 <div id="anchor"></div> 48 <div id="anchored"></div> 49 </div> 50 51 <script> 52 promise_test(async () => { 53 await waitUntilNextAnimationFrame(); 54 await waitUntilNextAnimationFrame(); 55 const anchoredStyle = getComputedStyle(anchored, "::before"); 56 assert_equals(anchoredStyle.top, "200px"); 57 }, "Starts rendering with flip-block"); 58 59 promise_test(async () => { 60 anchor.style.top = "150px"; 61 await waitUntilNextAnimationFrame(); 62 await waitUntilNextAnimationFrame(); 63 const anchoredStyle = getComputedStyle(anchored, "::before"); 64 assert_equals(anchoredStyle.top, "250px"); 65 }, "No successful position, keep flip-block"); 66 67 promise_test(async () => { 68 anchor.style.top = "200px"; 69 await waitUntilNextAnimationFrame(); 70 await waitUntilNextAnimationFrame(); 71 const anchoredStyle = getComputedStyle(anchored, "::before"); 72 assert_equals(anchoredStyle.top, "0px"); 73 }, "Base position without fallback now successful"); 74 </script>