| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>059 absolute image and containing block</title>
- <style>
- body { background: #ffffff; color: #202020; font-family: sans-serif;
- margin: 12px; font-size: 18px; }
- #outer { position: relative; margin-left: 100px; margin-top: 20px;
- width: 480px; height: 240px; background: #eeeeee;
- overflow: hidden; }
- #abs { position: absolute; top: 10px; left: 20px; width: 50px;
- height: 20px; background: #cc2222; }
- #poster { position: absolute; top: 0; left: 0; width: 100%;
- height: auto; }
- #result { background: #ffc8c8; color: #000000; padding: 8px;
- margin-top: 12px; }
- </style>
- </head>
- <body>
- <h1>059 — absolute image and containing block</h1>
- <p>An absolutely positioned poster must use its nearest positioned ancestor
- as the origin, and its percentage width must fill that block.</p>
- <div id="outer">
- <div id="abs"></div>
- <img id="poster" src="TILE.PNG" alt="">
- </div>
- <div id="result">checking...</div>
- <script>
- setTimeout(function () {
- function R(id) { return document.getElementById(id).getBoundingClientRect(); }
- var o = R('outer'), a = R('abs'), p = R('poster');
- var ok = Math.abs(a.left - (o.left + 20)) <= 2 &&
- Math.abs(a.top - (o.top + 10)) <= 2 &&
- Math.abs(p.left - o.left) <= 2 &&
- Math.abs(p.top - o.top) <= 2 &&
- Math.abs(p.width - o.width) <= 2;
- var r = document.getElementById('result');
- if (r) {
- r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
- r.textContent = (ok ? 'ABS-OK ' : 'ABS-FAIL ') +
- 'outer=' + Math.round(o.left) + ',' + Math.round(o.top) +
- ' abs=' + Math.round(a.left) + ',' + Math.round(a.top) +
- ' poster=' + Math.round(p.left) + ',' + Math.round(p.top) +
- ' ' + Math.round(p.width) + 'x' + Math.round(p.height);
- }
- }, 300);
- </script>
- </body>
- </html>
|