| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>041 calc</title>
- <style>
- html, body { margin: 0; padding: 0; background: #ffffff; color: #202020; }
- body { font-family: sans-serif; font-size: 13px; padding: 10px; }
- h1 { font-size: 20px; margin: 0 0 6px 0; }
- p { margin: 0 0 10px 0; }
- .pane { float: left; width: 440px; margin-left: 10px; }
- .label { background: #eeeeee; padding: 4px 6px; margin-bottom: 4px; }
- .stage { width: 300px; background: #f4f4f4; border: 1px solid #999999; padding: 6px; }
- .box { background: #cc3333; color: #ffffff; margin-bottom: 8px; }
- .box1 { margin-left: calc(10% + 8px); padding: calc(5% + 4px);
- height: calc(50% + 20px); }
- .ref1 { margin-left: 38px; padding: 19px; height: 170px; }
- .box2 { height: 10px; min-height: calc(20% + 10px); }
- .ref2 { height: 70px; }
- .box3 { max-width: calc(50% + 20px); height: 24px; }
- .ref3 { width: 170px; height: 24px; }
- .box4 { width: 50px; min-width: calc(30% + 10px); height: 24px; }
- .ref4 { width: 100px; height: 24px; }
- .box5 { height: 200px; max-height: calc(10% + 20px); }
- .ref5 { height: 50px; }
- #result { clear: both; margin-top: 14px; padding: 8px; background: #eeeeee;
- color: #000000; font-family: monospace; font-weight: bold; }
- </style>
- </head>
- <body>
- <h1>041 · calc in box metrics</h1>
- <p>Each A box must have the same box rectangle as its fixed-pixel B reference.</p>
- <div class="pane">
- <div class="label">A · calc()</div>
- <div class="stage" id="sa">
- <div class="box box1" id="a1">margin / padding / height</div>
- <div class="box box2" id="a2"></div>
- <div class="box box3" id="a3"></div>
- <div class="box box4" id="a4"></div>
- <div class="box box5" id="a5"></div>
- </div>
- </div>
- <div class="pane">
- <div class="label">B · reference</div>
- <div class="stage" id="sb">
- <div class="box ref1" id="b1">margin / padding / height</div>
- <div class="box ref2" id="b2"></div>
- <div class="box ref3" id="b3"></div>
- <div class="box ref4" id="b4"></div>
- <div class="box ref5" id="b5"></div>
- </div>
- </div>
- <div id="result">checking...</div>
- <script>
- setTimeout(function () {
- var sa = document.getElementById('sa').getBoundingClientRect();
- var sb = document.getElementById('sb').getBoundingClientRect();
- var ok = true, details = [];
- for (var i = 1; i <= 5; i++) {
- var a = document.getElementById('a' + i).getBoundingClientRect();
- var b = document.getElementById('b' + i).getBoundingClientRect();
- var aw = Math.round(a.width), bw = Math.round(b.width);
- var ah = Math.round(a.height), bh = Math.round(b.height);
- var ax = Math.round(a.left - sa.left), bx = Math.round(b.left - sb.left);
- if (Math.abs(aw - bw) > 1 || Math.abs(ah - bh) > 1 ||
- Math.abs(ax - bx) > 1) {
- ok = false;
- details.push(i + ': A=' + aw + 'x' + ah + '@' + ax +
- ' B=' + bw + 'x' + bh + '@' + bx);
- }
- }
- var out = document.getElementById('result');
- out.textContent = ok ? 'PASS: calc margins, padding and box sizes' :
- ('FAIL: ' + details.join('; '));
- out.style.background = ok ? '#ccffcc' : '#ffcccc';
- }, 600);
- </script>
- </body>
- </html>
|