064-structural-pseudo.html 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>064 structural pseudo-classes</title>
  6. <style>
  7. body { background: #ffffff; color: #202020; font-family: sans-serif;
  8. margin: 12px; font-size: 18px; }
  9. #list { padding-top: 30px; background: #f4f4f4; }
  10. #list > div { margin-top: 20px; padding-top: 10px; height: 30px;
  11. background: #dddddd; }
  12. #list > div:first-child { margin-top: 0; padding-top: 0; }
  13. #list > span { display: block; font-weight: bold; }
  14. #list > span:first-of-type { color: #00ff00; }
  15. #list > span:last-of-type { color: #0000ff; }
  16. #result { background: #ffc8c8; color: #000000; padding: 8px;
  17. margin-top: 12px; }
  18. </style>
  19. </head>
  20. <body>
  21. <h1>064 &mdash; structural pseudo-classes</h1>
  22. <p>A first child loses its own top margin/padding (the tagesschau first
  23. teaser uses this to sit directly under the header), and first/last of
  24. type select among siblings of the same tag.</p>
  25. <div id="list">
  26. <div id="a">A</div>
  27. <div id="b">B</div>
  28. <span id="s1">S1</span>
  29. <span id="s2">S2</span>
  30. </div>
  31. <div id="result">checking...</div>
  32. <script>
  33. setTimeout(function () {
  34. function R(id) { return document.getElementById(id).getBoundingClientRect(); }
  35. function C(id) { return getComputedStyle(document.getElementById(id)); }
  36. var list = R('list'), a = R('a'), b = R('b');
  37. var ok = Math.abs((a.top - list.top) - 30) <= 2 &&
  38. Math.abs((b.top - a.bottom) - 20) <= 2 &&
  39. C('s1').color === 'rgb(0, 255, 0)' &&
  40. C('s2').color === 'rgb(0, 0, 255)';
  41. var r = document.getElementById('result');
  42. if (r) {
  43. r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
  44. r.textContent = (ok ? 'PSEUDO-OK ' : 'PSEUDO-FAIL ') +
  45. 'a=' + Math.round(a.top - list.top) +
  46. ' gap=' + Math.round(b.top - a.bottom) +
  47. ' colors=' + C('s1').color + '/' + C('s2').color;
  48. }
  49. }, 300);
  50. </script>
  51. </body>
  52. </html>