| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>058 SVG viewBox and fill</title>
- <style>
- body { background: #ffffff; color: #202020; font-family: sans-serif;
- margin: 12px; font-size: 18px; }
- .icon { width: 60px; height: 60px; background: #eeeeee; }
- .wide { width: 150px; height: 30px; background: #eeeeee; margin-top: 8px; }
- #result { background: #ffc8c8; color: #000000; padding: 8px;
- margin-top: 12px; }
- </style>
- </head>
- <body>
- <h1>058 — SVG viewBox and fill</h1>
- <p>Fractional viewBox numbers must not truncate the height, and
- <code>width="100%"</code>/<code>fill</code> on a child must fill the box.</p>
- <div class="icon">
- <svg id="svg1" viewBox="0 0 340.16 340.16">
- <rect id="rect1" width="100%" height="100%" fill="#005AB4"></rect>
- </svg>
- </div>
- <div class="wide">
- <svg id="svg2" viewBox="0 0 692 140">
- <rect id="rect2" width="100%" height="100%" fill="#B00020"></rect>
- </svg>
- </div>
- <p><span id="c1" style="color:#005AB4">blue</span>
- <span id="c2" style="color:#B00020">red</span></p>
- <div id="result">checking...</div>
- <script>
- setTimeout(function () {
- function R(id) { return document.getElementById(id).getBoundingClientRect(); }
- /* SVG paint is `fill`, never the element's background. */
- function B(id) { return getComputedStyle(document.getElementById(id)).fill; }
- var s1 = R('svg1'), s2 = R('svg2');
- var r1 = B('rect1'), r2 = B('rect2');
- var ok = Math.abs(s1.width - 60) <= 2 &&
- Math.abs(s1.height - 60) <= 2 &&
- Math.abs(s2.width - 150) <= 2 &&
- Math.abs(s2.height - 30) <= 2 &&
- r1 === getComputedStyle(document.getElementById('c1')).color &&
- r2 === getComputedStyle(document.getElementById('c2')).color;
- var r = document.getElementById('result');
- if (r) {
- r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
- r.textContent = (ok ? 'SVG-OK ' : 'SVG-FAIL ') +
- 'icon=' + Math.round(s1.width) + 'x' +
- Math.round(s1.height) +
- ' wide=' + Math.round(s2.width) + 'x' +
- Math.round(s2.height) +
- ' fills=' + r1 + '/' + r2;
- }
- }, 300);
- </script>
- </body>
- </html>
|