position-area-value.html (1787B)
1 <!DOCTYPE html> 2 <title>CSS Anchor Positioning: <'position-area'> value</title> 3 <link rel="help" href="https://drafts.csswg.org/css-anchor-position-1/#position-try-fallbacks"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <style> 7 #cb { 8 position: relative; 9 width: 200px; 10 height: 200px; 11 border: 1px solid black; 12 } 13 #anchor { 14 position: absolute; 15 left: 100px; 16 top: 100px; 17 width: 80px; 18 height: 80px; 19 background-color: tomato; 20 anchor-name: --a; 21 } 22 #target, #ref { 23 position: absolute; 24 width: 40px; 25 height: 40px; 26 background-color: skyblue; 27 position-area: bottom right; 28 position-anchor: --a; 29 } 30 #ref { 31 background-color: seagreen; 32 } 33 </style> 34 <style id=style> 35 </style> 36 <div id=cb> 37 <div id=anchor></div> 38 <div id=target></div> 39 <div id=ref></div> 40 </div> 41 <script> 42 43 // Test that a given <'position-area'> produces the same result as a reference 44 // element that is styled with an position-area declaration directly. 45 function test_position_area_fn(position_area) { 46 test((t) => { 47 t.add_cleanup(() => { 48 style.textContent = ''; 49 }); 50 style.textContent = ` 51 #target { 52 position-try-fallbacks: ${position_area}; 53 } 54 #ref { 55 position-area: ${position_area}; 56 } 57 `; 58 assert_equals(target.offsetLeft, ref.offsetLeft, 'offsetLeft'); 59 assert_equals(target.offsetTop, ref.offsetTop, 'offsetTop'); 60 }, `${position_area}`); 61 } 62 63 test_position_area_fn('top left'); 64 test_position_area_fn('span-top left'); 65 test_position_area_fn('top span-left'); 66 test_position_area_fn('top center'); 67 test_position_area_fn('left center'); 68 test_position_area_fn('start center'); 69 test_position_area_fn('center start'); 70 71 </script>