049-table-layout.html 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>049 table width and alignment</title>
  6. <style>
  7. body { background: #ffffff; color: #202020; font-family: sans-serif;
  8. margin: 8px; }
  9. table { border: 1px solid #404040; border-collapse: collapse; }
  10. td { padding: 4px; font-size: 16px; }
  11. </style>
  12. </head>
  13. <body>
  14. <h1>049 &mdash; table width and alignment</h1>
  15. <p>The outer table is 85% of the body; its single-column cell fills that
  16. width. The nested table is 100% of the cell. Cell text stays left-aligned
  17. even inside <code>&lt;center&gt;</code>, and <code>align="right"</code>
  18. right-aligns the rank column.</p>
  19. <center>
  20. <table id="outer" width="85%">
  21. <tr><td id="outercell" style="background: #ffdddd">OUTER CELL FILLS 85%</td></tr>
  22. <tr><td>
  23. <table id="story" width="100%">
  24. <tr>
  25. <td id="rank" align="right" style="background: #ffeecc">1.</td>
  26. <td style="background: #eeeeff">vote</td>
  27. <td style="background: #eeffee">NESTED TITLE FILLS THE CELL</td>
  28. </tr>
  29. </table>
  30. </td></tr>
  31. </table>
  32. </center>
  33. <div id="result" style="background: #ffc8c8; color: #000000; padding: 8px;
  34. font-size: 18px;">checking...</div>
  35. <script>
  36. setTimeout(function () {
  37. var body = document.body.getBoundingClientRect();
  38. var outer = document.getElementById('outer').getBoundingClientRect();
  39. var cell = document.getElementById('outercell').getBoundingClientRect();
  40. var story = document.getElementById('story').getBoundingClientRect();
  41. var rank = document.getElementById('rank').getBoundingClientRect();
  42. var want = body.width * 85 / 100;
  43. var ok = Math.abs(outer.width - want) <= 12;
  44. ok = ok && Math.abs(cell.width - outer.width) <= 12;
  45. ok = ok && Math.abs(story.width - outer.width) <= 16;
  46. ok = ok && rank.width < outer.width / 2;
  47. var r = document.getElementById('result');
  48. if (r) {
  49. r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
  50. r.textContent = (ok ? 'TABLE-OK ' : 'TABLE-FAIL ') +
  51. 'body=' + Math.round(body.width) +
  52. ' outer=' + Math.round(outer.width) +
  53. ' cell=' + Math.round(cell.width) +
  54. ' story=' + Math.round(story.width) +
  55. ' rank=' + Math.round(rank.width);
  56. }
  57. }, 300);
  58. </script>
  59. </body>
  60. </html>