046-flex-footer-query.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>046 flex footer and query selectors</title>
  6. <style>
  7. html, body { margin: 0; padding: 0; background: #f6f6ef; color: #202020; }
  8. body { font-family: sans-serif; font-size: 13px; padding: 10px; }
  9. h1 { font-size: 20px; margin: 0 0 6px 0; }
  10. p { margin: 0 0 10px 0; }
  11. .nav { clear: both; overflow: hidden; margin-bottom: 14px; }
  12. .nav ul { float: right; margin: 0; padding: 0; list-style: none; }
  13. .nav li { float: left; margin-left: 8px; }
  14. .nav a { display: block; color: #404040; padding: 10px 15px; text-decoration: none; }
  15. .nav a.btn { background: #28cb75; color: #ffffff; font-weight: bold;
  16. border: 2px solid #28cb75; border-radius: 20px; }
  17. .flexfooter { display: flex; flex-direction: row; justify-content: space-evenly;
  18. max-width: 1000px; margin: 0 auto; text-align: left;
  19. flex-wrap: wrap; background: #494f5a; color: #ffffff;
  20. padding: 20px; }
  21. .list h3 { color: #acacac; margin: 0 0 10px 0; }
  22. .list a { display: block; color: #ffffff; margin-bottom: 4px; text-decoration: none; }
  23. .list.wide a { white-space: nowrap; }
  24. #result { margin-top: 14px; padding: 8px; background: #eeeeee; color: #000000;
  25. font-family: monospace; font-weight: bold; }
  26. </style>
  27. </head>
  28. <body>
  29. <h1>046 &middot; flex footer and query selectors</h1>
  30. <p>The three footer columns must sit on one row with equal space, and the padded Install button must stay on one line.</p>
  31. <div class="nav">
  32. <ul>
  33. <li><a href="#">Demo</a></li>
  34. <li><a href="#">Docs</a></li>
  35. <li><a class="btn" id="install" href="#">Install</a></li>
  36. <li><a href="#">My Account</a></li>
  37. </ul>
  38. </div>
  39. <div class="flexfooter" id="footer">
  40. <div class="list wide" id="l1"><h3>About</h3><a href="#">Story</a><a href="#">Open Source</a><a href="#">Imprint</a><a href="#">Brand Assets</a><a href="#">Data Processing Agreement</a></div>
  41. <div class="list" id="l2"><h3>Resources</h3><a href="#">Blog</a><a href="#">Documentation</a><a href="#">Forum</a><a href="#">Pricing</a><a href="#">Community apps</a><a href="#">App Status</a></div>
  42. <div class="list" id="l3"><h3>Follow us</h3><a href="#">Forum</a><a href="#">Mastodon</a><a href="#">RSS</a></div>
  43. </div>
  44. <div id="result">checking...</div>
  45. <script>
  46. setTimeout(function () {
  47. var lists = document.querySelectorAll('.list');
  48. var b1 = document.getElementById('l1').getBoundingClientRect();
  49. var b2 = document.getElementById('l2').getBoundingClientRect();
  50. var b3 = document.getElementById('l3').getBoundingClientRect();
  51. var ins = document.getElementById('install');
  52. var ir = ins.getBoundingClientRect();
  53. var q = document.querySelector('a.btn');
  54. var details = [];
  55. var ok = lists.length === 3;
  56. if (!ok) details.push('list count=' + lists.length);
  57. if (lists.length && lists[0].tagName !== 'DIV') {
  58. ok = false; details.push('query element tag=' + lists[0].tagName);
  59. }
  60. if (!q || q.tagName !== 'A' || q.textContent !== 'Install') {
  61. ok = false; details.push('querySelector anchor');
  62. }
  63. if (Math.abs(b1.top - b2.top) > 1 || Math.abs(b2.top - b3.top) > 1) {
  64. ok = false; details.push('footer rows differ');
  65. }
  66. var gap1 = b2.left - b1.right;
  67. var gap2 = b3.left - b2.right;
  68. if (Math.abs(gap1 - gap2) > 3) {
  69. ok = false; details.push('gaps ' + Math.round(gap1) + '/' + Math.round(gap2));
  70. }
  71. if (ir.height > 50 || ir.width < 70) {
  72. ok = false; details.push('install ' + Math.round(ir.width) + 'x' + Math.round(ir.height));
  73. }
  74. var out = document.getElementById('result');
  75. out.textContent = ok ? 'PASS: footer columns, padding and query selectors' :
  76. ('FAIL: ' + details.join('; '));
  77. out.style.background = ok ? '#ccffcc' : '#ffcccc';
  78. }, 600);
  79. </script>
  80. </body>
  81. </html>