container-units-small-viewport-fallback.html (2330B)
1 <!doctype html> 2 <title>Container Relative Units: fall back to small viewport</title> 3 <link rel="help" href="https://drafts.csswg.org/css-conditional-5/#container-lengths"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="support/cq-testcommon.js"></script> 7 <style> 8 iframe { 9 width: 200px; 10 height: 40px; 11 } 12 </style> 13 <iframe id=iframe srcdoc=" 14 <style> 15 #container { 16 container-type: inline-size; 17 width: 70px; 18 height: 30px; 19 } 20 #target { 21 left: 10cqw; 22 top: 10cqh; 23 right: 10cqi; 24 bottom: 10cqb; 25 margin-left: 10cqmax; 26 margin-right: 10cqmin; 27 } 28 </style> 29 <div id=container> 30 <div id=target></div> 31 </div> 32 "></iframe> 33 34 <script> 35 setup(() => assert_implements_size_container_queries()); 36 37 function waitForLoad(w) { 38 return new Promise(resolve => w.addEventListener('load', resolve)); 39 } 40 41 promise_test(async () => { 42 await waitForLoad(window); 43 let inner_target = iframe.contentDocument.querySelector('#target'); 44 45 // Since there's an inline-size container, cqw/cqi should evaluate against 46 // that. 47 assert_equals(getComputedStyle(inner_target).left, '7px'); // 10cqw 48 assert_equals(getComputedStyle(inner_target).right, '7px'); // 10cqi 49 50 // However, there is no size container, so cqh/cqb should evaluate against 51 // the small viewport size. 52 assert_equals(getComputedStyle(inner_target).top, '4px'); // 10cqh 53 assert_equals(getComputedStyle(inner_target).bottom, '4px'); // 10cqb 54 55 assert_equals(getComputedStyle(inner_target).marginLeft, '7px'); // 10cqmax 56 assert_equals(getComputedStyle(inner_target).marginRight, '4px'); // 10cqmin 57 58 iframe.style = 'width:400px;height:80px'; 59 60 // Not affected by resize: 61 assert_equals(getComputedStyle(inner_target).left, '7px'); // 10cqw 62 assert_equals(getComputedStyle(inner_target).right, '7px'); // 10cqi 63 64 // Affected: 65 assert_equals(getComputedStyle(inner_target).top, '8px'); // 10cqh 66 assert_equals(getComputedStyle(inner_target).bottom, '8px'); // 10cqb 67 assert_equals(getComputedStyle(inner_target).marginLeft, '8px'); // 10cqmax 68 assert_equals(getComputedStyle(inner_target).marginRight, '7px'); // 10cqmin 69 }, 'Use small viewport size as fallback'); 70 </script>