061-inline-width.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>061 inline width and intrinsic flex size</title>
  6. <style>
  7. body { background: #ffffff; color: #202020; font-family: sans-serif;
  8. margin: 12px; font-size: 18px; }
  9. #bar { display: flex; align-items: center; width: 620px; height: 60px;
  10. overflow: hidden; background: #f4f4f4; }
  11. #main { z-index: 2; }
  12. #home { margin: 0 3px 0 0; }
  13. #homeLink { display: block; padding: 11px 12px; }
  14. /* the tagesschau mobile icon-only idiom: a 1px inline label */
  15. #label { display: inline; position: relative; width: 1px; height: 1px;
  16. overflow: hidden; }
  17. #sub { width: 100%; overflow: hidden; background: #e8e8ff; }
  18. #sub ul { list-style: none; margin: 0; padding: 0; display: flex; }
  19. #sub li { white-space: nowrap; padding: 4px 10px; }
  20. #result { background: #ffc8c8; color: #000000; padding: 8px;
  21. margin-top: 12px; }
  22. </style>
  23. </head>
  24. <body>
  25. <h1>061 &mdash; inline width and intrinsic flex size</h1>
  26. <p>Width/height do not apply to a non-replaced inline box. A 1px inline
  27. label must not shrink its block ancestor, and the flex row must size the
  28. left item from the real text width.</p>
  29. <div id="bar">
  30. <div id="main">
  31. <div id="home">
  32. <a id="homeLink" href="#"><span id="label">Startseite</span></a>
  33. </div>
  34. </div>
  35. <div id="sub"><ul><li>Aigner</li><li>Ukraine</li><li>Klima</li></ul></div>
  36. </div>
  37. <div id="result">checking...</div>
  38. <script>
  39. setTimeout(function () {
  40. function R(id) { return document.getElementById(id).getBoundingClientRect(); }
  41. var main = R('main'), link = R('homeLink');
  42. var bar = R('bar'), sub = R('sub');
  43. /* getBoundingClientRect() reports no box for a plain inline span, so
  44. check that the label is still inline and that its text gave the link
  45. a text-sized box. */
  46. var labelInline = getComputedStyle(document.getElementById('label')).display;
  47. var ok = main.width > 80 &&
  48. link.width > 80 &&
  49. labelInline === 'inline' &&
  50. Math.abs(bar.height - 60) <= 2 &&
  51. sub.left >= main.right - 2;
  52. var r = document.getElementById('result');
  53. if (r) {
  54. r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
  55. r.textContent = (ok ? 'INLINE-WIDTH-OK ' : 'INLINE-WIDTH-FAIL ') +
  56. 'main=' + Math.round(main.width) +
  57. ' link=' + Math.round(link.width) +
  58. ' label=' + labelInline +
  59. ' sub=' + Math.round(sub.left);
  60. }
  61. }, 300);
  62. </script>
  63. </body>
  64. </html>