| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>057 flex outer widths</title>
- <style>
- body { background: #ffffff; color: #202020; font-family: sans-serif;
- margin: 12px; font-size: 18px; }
- #row { display: flex; width: 600px; height: 80px; background: #eeeeee; }
- #a { width: 100px; margin-left: 20px; margin-right: 10px; padding: 5px;
- background: #ffdddd; }
- #b { flex-grow: 1; background: #ddffdd; }
- #nowrap { display: flex; width: 600px; height: 30px; background: #eeeeff;
- margin-top: 12px; }
- #nowrap > div { width: 300px; height: 20px; background: #ddddff;
- margin-right: 10px; }
- #result { background: #ffc8c8; color: #000000; padding: 8px;
- margin-top: 12px; }
- </style>
- </head>
- <body>
- <h1>057 — flex outer widths and default nowrap</h1>
- <p>Explicit widths are content-box sizes: the flex line must include the
- item's margins, padding and borders. A flex row without
- <code>flex-wrap</code> must stay on one line.</p>
- <div id="row"><div id="a">A</div><div id="b">B</div></div>
- <div id="nowrap"><div>1</div><div>2</div><div>3</div></div>
- <div id="result">checking...</div>
- <script>
- setTimeout(function () {
- function R(id) { return document.getElementById(id).getBoundingClientRect(); }
- var a = R('a'), b = R('b');
- var n = document.getElementById('nowrap').children;
- var n0 = n[0].getBoundingClientRect();
- var n2 = n[2].getBoundingClientRect();
- /* In one nowrap row the third 300px item overflows past the first two
- (x > 500); if it wrapped it would start back at the container's left. */
- var same_row = n2.left > n0.left + 500;
- var ok = Math.abs(a.width - 110) <= 2 &&
- Math.abs(b.width - 460) <= 10 &&
- b.left > a.left + 100 &&
- same_row;
- var r = document.getElementById('result');
- if (r) {
- r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
- r.textContent = (ok ? 'FLEX-OK ' : 'FLEX-FAIL ') +
- 'a=' + Math.round(a.left) + ',' + Math.round(a.width) +
- ' b=' + Math.round(b.left) + ',' + Math.round(b.width) +
- ' nowrap=' + same_row;
- }
- }, 300);
- </script>
- </body>
- </html>
|