068-rem-line-height.html 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>068 rem line-height</title>
  6. <style>
  7. html { font-size: 62.5%; }
  8. body { background: #ffffff; color: #202020; font-family: sans-serif;
  9. margin: 12px; font-size: 18px; }
  10. #a { font-size: 1.8rem; line-height: 2.4rem; margin: 0;
  11. background: #e0e0ff; }
  12. #b { font-size: 18px; line-height: 24px; margin: 8px 0 0 0;
  13. background: #e0ffe0; }
  14. #result { background: #ffc8c8; color: #000000; padding: 8px;
  15. margin-top: 12px; }
  16. </style>
  17. </head>
  18. <body>
  19. <h1>068 &mdash; rem line-height</h1>
  20. <p>With a 10px root, <code>line-height: 2.4rem</code> is 24px, not a 2.4&times;
  21. multiplier. Both blocks must be the same height.</p>
  22. <p id="a">one<br>two<br>three</p>
  23. <p id="b">one<br>two<br>three</p>
  24. <div id="result">checking...</div>
  25. <script>
  26. setTimeout(function () {
  27. function R(id) { return document.getElementById(id).getBoundingClientRect(); }
  28. var a = R('a'), b = R('b');
  29. var ok = Math.abs(a.height - b.height) <= 2 && a.height < 100;
  30. var r = document.getElementById('result');
  31. if (r) {
  32. r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
  33. r.textContent = (ok ? 'REMLH-OK ' : 'REMLH-FAIL ') + 'a=' +
  34. Math.round(a.height) + ' b=' + Math.round(b.height);
  35. }
  36. }, 300);
  37. </script>
  38. </body>
  39. </html>