getComputedStyle-calc-mixed-units-003.html (2510B)
1 <!DOCTYPE html> 2 3 <meta charset="UTF-8"> 4 5 <title>CSS Values Test: computed value of calc() values using multiplication/division with mixed units</title> 6 7 <link rel="help" href="https://www.w3.org/TR/css-values-4/#calc-computed-value"> 8 9 <meta name="flags" content=""> 10 <meta content="This meta-test checks for the resolution and absolutization of computed values with mixed units to 'px' when multiplication/division is used." name="assert"> 11 12 <script src="/resources/testharness.js"></script> 13 <script src="/resources/testharnessreport.js"></script> 14 15 <style> 16 html { 17 font-size: 30px; 18 } 19 20 body { 21 font-size: 16px; 22 line-height: 1.25; /* computed value: 20px */ 23 width: 520px; 24 height: 500px; 25 margin: 20px; 26 } 27 28 div#target { 29 height: 100px; 30 width: 100px; 31 } 32 </style> 33 34 <div id="target"></div> 35 36 <script> 37 function startTesting() { 38 var targetElement = document.getElementById("target"); 39 40 function verifyComputedStyle(property_name, specified_value, expected_value) { 41 test(function() { 42 targetElement.style.setProperty(property_name, "initial"); 43 targetElement.style.setProperty(property_name, specified_value); 44 assert_equals(getComputedStyle(targetElement)[property_name], expected_value); 45 }, `testing ${property_name}: ${specified_value}`); 46 } 47 48 verifyComputedStyle("width", "calc(5px * 10lh / 1px)", "1000px"); 49 /* 50 10lh = 200px 51 5px * 200px / 1px = 1000px^2 / 1px = 1000px 52 Total = 1000px 53 */ 54 55 verifyComputedStyle("width", "calc(20% * 0.5em / 1px)", "832px"); 56 /* 57 20% of 520px = 104px 58 0.5em = 8px 59 104px * 8px / 1px = 832px^2 / 1px = 832px 60 Total = 832px 61 */ 62 63 verifyComputedStyle("width", "calc(4px * 4em / 1px)", "256px"); 64 /* 65 4em = 64px 66 4px * 64px / 1px = 256px^2 / 1px = 256px 67 Total = 256px 68 */ 69 70 verifyComputedStyle("width", "calc(400px / 4lh * 1px)", "5px"); 71 /* 72 4lh = 80px 73 400px / 80px * 1px = 5 * 1px = 5px 74 Total = 5px 75 */ 76 77 verifyComputedStyle("width", "calc(20% / 0.5em * 1px)", "13px"); 78 /* 79 20% of 520px = 104px 80 0.5em = 8px 81 104px / 8px * 1px = 13 * 1px = 13px 82 Total = 13px 83 */ 84 85 verifyComputedStyle("width", "calc(52px * 1px / 10%)", "1px"); 86 /* 87 10% of 520px = 52px 88 52px * 1px / 52px = 1px 89 Total = 1px 90 */ 91 92 verifyComputedStyle("width", "calc(100px * 1px / 1px / 1)", "100px"); 93 } 94 95 startTesting(); 96 97 </script>