| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>064 structural pseudo-classes</title>
- <style>
- body { background: #ffffff; color: #202020; font-family: sans-serif;
- margin: 12px; font-size: 18px; }
- #list { padding-top: 30px; background: #f4f4f4; }
- #list > div { margin-top: 20px; padding-top: 10px; height: 30px;
- background: #dddddd; }
- #list > div:first-child { margin-top: 0; padding-top: 0; }
- #list > span { display: block; font-weight: bold; }
- #list > span:first-of-type { color: #00ff00; }
- #list > span:last-of-type { color: #0000ff; }
- #result { background: #ffc8c8; color: #000000; padding: 8px;
- margin-top: 12px; }
- </style>
- </head>
- <body>
- <h1>064 — structural pseudo-classes</h1>
- <p>A first child loses its own top margin/padding (the tagesschau first
- teaser uses this to sit directly under the header), and first/last of
- type select among siblings of the same tag.</p>
- <div id="list">
- <div id="a">A</div>
- <div id="b">B</div>
- <span id="s1">S1</span>
- <span id="s2">S2</span>
- </div>
- <div id="result">checking...</div>
- <script>
- setTimeout(function () {
- function R(id) { return document.getElementById(id).getBoundingClientRect(); }
- function C(id) { return getComputedStyle(document.getElementById(id)); }
- var list = R('list'), a = R('a'), b = R('b');
- var ok = Math.abs((a.top - list.top) - 30) <= 2 &&
- Math.abs((b.top - a.bottom) - 20) <= 2 &&
- C('s1').color === 'rgb(0, 255, 0)' &&
- C('s2').color === 'rgb(0, 0, 255)';
- var r = document.getElementById('result');
- if (r) {
- r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
- r.textContent = (ok ? 'PSEUDO-OK ' : 'PSEUDO-FAIL ') +
- 'a=' + Math.round(a.top - list.top) +
- ' gap=' + Math.round(b.top - a.bottom) +
- ' colors=' + C('s1').color + '/' + C('s2').color;
- }
- }, 300);
- </script>
- </body>
- </html>
|