1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
<!DOCTYPE html>
<meta charset="UTF-8">
<title>CSS Values Test: computed value of 8 calc() values that involve mixed units</title>
<link rel="author" title="Gérard Talbot" href="http://www.gtalbot.org/BrowserBugsSection/css21testsuite/">
<link rel="help" href="https://www.w3.org/TR/css-values-4/#calc-computed-value">
<meta name="flags" content="">
<meta content="This meta-test verifies that terms with a length value that can be resolved at computed-value time must be resolved and must be absolutized to 'px'. In this meta-test, we test percentage unit (%), three font-relative length units (em, rem, lh) and some absolute length units (pc, pt, px, cm, mm, Q, in). " name="assert">
<!--
NOT Tested in this test are:
Viewport-percentage Length units:
vh, svh, lvh, dvh,
vw, svw, lvw, dvw,
vmin, svmin, lvmin, dvmin,
vmax, svmax, lvmax, dvmax,
vi, svi, lvi, dvi,
vb, svb, lvb, dvb
and these of font-relative length units:
ex, rex,
cap, rcap,
ch, rch,
ic, ric,
rlh
-->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
html
{
font-size: 30px; /* for checking rem unit */
}
body
{
font-size: 16px;
line-height: 1.25; /* computed value: 20px; for checking lh unit */
height: 500px;
margin: 20px;
width: 520px;
}
div#target
{
height: 100px;
width: 100px;
}
</style>
<div id="target"></div>
<script>
function startTesting()
{
var targetElement = document.getElementById("target");
function verifyComputedStyle(property_name, specified_value, expected_value)
{
test(function()
{
targetElement.style.setProperty(property_name, "initial");
targetElement.style.setProperty(property_name, specified_value);
assert_equals(getComputedStyle(targetElement)[property_name], expected_value);
}, `testing ${property_name}: ${specified_value}`);
}
verifyComputedStyle("width", "calc(10% + 2em)", "84px");
/*
520px mult 10% == 52px
+
16px mult 2 == 32px
=======
84px
*/
verifyComputedStyle("width", "calc(5% + 4rem)", "146px");
/*
520px mult 5% == 26px
+
30px mult 4 == 120px
=======
146px
*/
verifyComputedStyle("width", "calc(8lh + 7px)", "167px");
/*
8 mult 20px == 160px
+
7px
=======
167px
*/
verifyComputedStyle("height", "calc(10% + 6pt)", "58px");
/*
10% mult 500 == 50px
+
6pt == 8px
========
58px
*/
verifyComputedStyle("width", "calc(4em + 2.6458333cm)", "164px");
/*
4 mult 16px == 64px
+
2.6458333cm == 100px
========
164px
*/
verifyComputedStyle("height", "calc(5em + 26.458333mm)", "180px");
/*
5 mult 16px == 80px
+
26.458333mm == 100px
========
180px
*/
verifyComputedStyle("width", "calc(2in + 101.6Q)", "288px");
/*
2 mult 96px == 192px
+
101.6Q == 96px
========
288px
*/
verifyComputedStyle("height", "calc(1pc + 3pt)", "20px");
/*
1pc == 16px
+
3pt == 4px
=======
20px
*/
}
startTesting();
</script>
|