062-flex-link-box.html 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>062 flex container on an inline element</title>
  6. <style>
  7. body { background: #ffffff; color: #202020; font-family: sans-serif;
  8. margin: 12px; font-size: 18px; }
  9. /* an <a> is inline by tag but a flex container is block-level */
  10. #card { display: flex; width: 520px; background: #eeeeee; }
  11. #thumb { width: 90px; height: 90px; background: #cccccc; }
  12. #body { flex-grow: 1; }
  13. #h { margin: 0 0 4px; font-size: 22px; }
  14. #p { margin: 0; }
  15. #after { background: #ddffdd; }
  16. #result { background: #ffc8c8; color: #000000; padding: 8px;
  17. margin-top: 12px; }
  18. </style>
  19. </head>
  20. <body>
  21. <h1>062 &mdash; flex container on an inline element</h1>
  22. <p>A link card uses <code>&lt;a style="display:flex"&gt;</code>: the link must
  23. get a block-level box with a real height and the next block must start
  24. below it.</p>
  25. <a id="card" href="#">
  26. <div id="thumb"></div>
  27. <div id="body"><h2 id="h">Headline</h2><p id="p">Teaser text body</p></div>
  28. </a>
  29. <div id="after">after the card</div>
  30. <div id="result">checking...</div>
  31. <script>
  32. setTimeout(function () {
  33. function R(id) { return document.getElementById(id).getBoundingClientRect(); }
  34. var card = R('card'), body = R('body'), h = R('h'), after = R('after');
  35. var ok = card.height >= 88 &&
  36. card.width >= 500 &&
  37. body.width > 350 &&
  38. h.height > 10 &&
  39. after.top >= card.bottom - 1;
  40. var r = document.getElementById('result');
  41. if (r) {
  42. r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
  43. r.textContent = (ok ? 'FLEX-LINK-OK ' : 'FLEX-LINK-FAIL ') +
  44. 'card=' + Math.round(card.width) + 'x' +
  45. Math.round(card.height) +
  46. ' body=' + Math.round(body.width) +
  47. ' h=' + Math.round(h.height) +
  48. ' after=' + Math.round(after.top);
  49. }
  50. }, 300);
  51. </script>
  52. </body>
  53. </html>