clamp-length-computed.html (2010B)
1 <!DOCTYPE html> 2 <link rel="help" href="https://drafts.csswg.org/css-values-4/#comp-func"> 3 <link rel="author" title="Xiaocheng Hu" href="mailto:xiaochengh@chromium.org"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="../support/computed-testcommon.js"></script> 7 <div id="container" style="font-size: 20px"> 8 <div id="target"></div> 9 <div id="reference"></div> 10 </div> 11 <script> 12 const property = 'letter-spacing'; 13 14 function test_length_equals(value, expected) { 15 const reference = document.getElementById('reference'); 16 reference.style[property] = ''; 17 reference.style[property] = expected; 18 const computed = getComputedStyle(reference)[property]; 19 test_computed_value(property, value, computed); 20 } 21 22 test_length_equals('clamp(10px, 20px, 30px)', '20px'); 23 test_length_equals('clamp(10px, 5px, 30px)', '10px'); 24 test_length_equals('clamp(10px, 35px, 30px)', '30px'); 25 test_length_equals('clamp(10px, 35px , 30px)', '30px'); 26 test_length_equals('clamp(10px, 35px /*foo*/, 30px)', '30px'); 27 test_length_equals('clamp(10px /* foo */ , 35px, 30px)', '30px'); 28 test_length_equals('clamp(10px , 35px, 30px)', '30px'); 29 30 // clamp(MIN, VAL, MAX) is identical to max(MIN, min(VAL, MAX)), 31 // so MIN wins over MAX if they are in the wrong order. 32 test_length_equals('clamp(30px, 100px, 20px)', '30px'); 33 34 // also test with negative values 35 test_length_equals('clamp(-30px, -20px, -10px)', '-20px'); 36 test_length_equals('clamp(-30px, -100px, -10px)', '-30px'); 37 test_length_equals('clamp(-30px, 100px, -10px)', '-10px'); 38 test_length_equals('clamp(-10px, 100px, -30px)', '-10px'); 39 test_length_equals('clamp(-10px, -100px, -30px)', '-10px'); 40 41 // and negating the result of clamp 42 test_length_equals('calc(0px + clamp(10px, 20px, 30px))', '20px'); 43 test_length_equals('calc(0px - clamp(10px, 20px, 30px))', '-20px'); 44 test_length_equals('calc(0px + clamp(30px, 100px, 20px))', '30px'); 45 test_length_equals('calc(0px - clamp(30px, 100px, 20px))', '-30px'); 46 47 </script>