056-details-summary.html 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>056 details summary</title>
  6. <style>
  7. body { background: #ffffff; color: #202020; font-family: sans-serif;
  8. margin: 12px; font-size: 18px; }
  9. summary { background: #eeeeff; padding: 6px; }
  10. #hidden-content { background: #ffdddd; padding: 6px; }
  11. #open-content { background: #ddffdd; padding: 6px; }
  12. #result { background: #ffc8c8; color: #000000; padding: 8px;
  13. margin-top: 12px; }
  14. </style>
  15. </head>
  16. <body>
  17. <h1>056 &mdash; closed details keeps its summary</h1>
  18. <p>A closed <code>&lt;details&gt;</code> must keep the summary (the hamburger
  19. button on many news sites) in the layout and hide only the rest.</p>
  20. <details id="closed">
  21. <summary id="closed-summary">CLOSED SUMMARY</summary>
  22. <div id="hidden-content">THIS MUST BE HIDDEN</div>
  23. </details>
  24. <details id="open" open>
  25. <summary id="open-summary">OPEN SUMMARY</summary>
  26. <div id="open-content">THIS MUST BE VISIBLE</div>
  27. </details>
  28. <div id="result">checking...</div>
  29. <script>
  30. setTimeout(function () {
  31. var s = document.getElementById('closed-summary');
  32. var h = document.getElementById('hidden-content');
  33. var o = document.getElementById('open-content');
  34. var sr = s.getBoundingClientRect();
  35. var hd = getComputedStyle(h).display;
  36. var od = getComputedStyle(o).display;
  37. var ok = sr.width > 50 && sr.height > 0 &&
  38. hd === 'none' && od !== 'none';
  39. var r = document.getElementById('result');
  40. if (r) {
  41. r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
  42. r.textContent = (ok ? 'DETAILS-OK ' : 'DETAILS-FAIL ') +
  43. 'summary=' + Math.round(sr.width) + 'x' +
  44. Math.round(sr.height) +
  45. ' hidden=' + hd + ' open=' + od;
  46. }
  47. }, 300);
  48. </script>
  49. </body>
  50. </html>