calc-size-height.html (3115B)
1 <!DOCTYPE html> 2 <title>calc-size() on height</title> 3 <link rel="help" href="https://drafts.csswg.org/css-values-5/#calc-size"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <style> 7 #container { 8 font-size: 20px; 9 } 10 #child { 11 width: 123px; 12 height: 10px; 13 } 14 </style> 15 16 <div id="container"> 17 <div id="target"> 18 <div id="child"></div> 19 </div> 20 </div> 21 22 <script> 23 24 let basic_tests = [ 25 { value: "calc-size(any, 357px)", expected: "357px" }, 26 { value: "calc-size(any, 31%)", expected_auto: "0px", expected_definite: "31px" }, 27 { value: "calc-size(31%, size)", expected_auto: "10px", expected_definite: "31px" }, 28 { value: "calc-size(max-content, 31%)", expected_auto: "0px", expected_definite: "31px" }, 29 { value: "calc-size(fit-content, 72px)", expected: "72px" }, 30 { value: "calc-size(37px, 93px)", expected: "93px" }, 31 { value: "calc-size(83px, size * 3)", expected: "249px" }, 32 { value: "calc-size(min-content, size / 2)", expected: "5px" }, 33 { value: "calc-size(max-content, size * 1.2)", expected: "12px" }, 34 { value: "calc-size(fit-content, size / 2 + 30px)", expected: "35px" }, 35 { value: "calc-size(30px, 15em)", expected: "300px" }, 36 { value: "calc-size(calc-size(any, 30px), 15em)", expected: "300px" }, 37 { value: "calc-size(calc-size(2in, 30px), 15em)", expected: "300px" }, 38 { value: "calc-size(calc-size(any, 300px), size * 2)", expected: "600px" }, 39 { value: "calc-size(calc-size(min-content, 30px), 15em)", expected: "300px" }, 40 { value: "calc-size(calc-size(min-content, size), size)", expected: "10px" }, 41 { value: "calc-size(any, 31% + 12px)", expected_auto: "12px", expected_definite: "43px" }, 42 { value: "calc-size(auto, size * 1.5)", expected: "15px" }, 43 ]; 44 const container = document.getElementById("container"); 45 const target = document.getElementById("target"); 46 const target_cs = getComputedStyle(target); 47 const child = document.getElementById("child"); 48 const child_cs = getComputedStyle(child); 49 for (const obj of basic_tests) { 50 test((t) => { 51 target.style.removeProperty("height"); 52 target.style.height = obj.value; 53 container.style.height = "auto"; 54 let expected = "expected" in obj ? obj.expected : obj.expected_auto; 55 assert_equals(target_cs.height, expected); 56 }, `resolved height for height in auto height container: ${obj.value}`); 57 test((t) => { 58 target.style.removeProperty("height"); 59 target.style.height = obj.value; 60 container.style.height = "100px"; 61 let expected = "expected" in obj ? obj.expected : obj.expected_definite; 62 assert_equals(target_cs.height, expected); 63 }, `resolved height for height in definite height container: ${obj.value}`); 64 } 65 66 test((t) => { 67 t.add_cleanup(() => { 68 child.style.height = ""; 69 child.innerHTML = ""; 70 }); 71 container.style.height = "auto"; 72 target.style.height = "calc-size(min-content, size + 23px)"; 73 child.style.height = "100%"; 74 child.innerHTML = "<div style='height: 7px'></div>"; 75 assert_equals(child_cs.height, "7px"); 76 }, "calc-size() is indefinite when the intrinsic size is indefinite"); 77 78 </script>