027-sticky.html 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>027 position: sticky</title>
  6. <style>
  7. html, body { margin: 0; padding: 0; background: #ffffff; color: #202020; }
  8. body { font-family: sans-serif; font-size: 14px; }
  9. h1 { font-size: 20px; margin: 10px 0 4px 10px; }
  10. p { margin: 0 0 12px 10px; }
  11. .header { position: sticky; top: 0; height: 40px; background: #333333; color: #ffffff; padding: 8px; font-size: 18px; }
  12. .content { padding: 0 10px; }
  13. .after { background: #cc3333; color: #ffffff; height: 30px; margin-top: 20px; padding: 6px; }
  14. </style>
  15. </head>
  16. <body>
  17. <h1>027 &middot; position: sticky</h1>
  18. <p>Scroll down: the dark header must stay at the top of the page area.</p>
  19. <div class="header">Sticky header</div>
  20. <div class="content">
  21. <p>Line 1: the quick brown fox jumps over the lazy dog.</p>
  22. <p>Line 2: the quick brown fox jumps over the lazy dog.</p>
  23. <p>Line 3: the quick brown fox jumps over the lazy dog.</p>
  24. <p>Line 4: the quick brown fox jumps over the lazy dog.</p>
  25. <p>Line 5: the quick brown fox jumps over the lazy dog.</p>
  26. <p>Line 6: the quick brown fox jumps over the lazy dog.</p>
  27. <p>Line 7: the quick brown fox jumps over the lazy dog.</p>
  28. <p>Line 8: the quick brown fox jumps over the lazy dog.</p>
  29. <p>Line 9: the quick brown fox jumps over the lazy dog.</p>
  30. <p>Line 10: the quick brown fox jumps over the lazy dog.</p>
  31. <p>Line 11: the quick brown fox jumps over the lazy dog.</p>
  32. <p>Line 12: the quick brown fox jumps over the lazy dog.</p>
  33. <p>Line 13: the quick brown fox jumps over the lazy dog.</p>
  34. <p>Line 14: the quick brown fox jumps over the lazy dog.</p>
  35. <p>Line 15: the quick brown fox jumps over the lazy dog.</p>
  36. <p>Line 16: the quick brown fox jumps over the lazy dog.</p>
  37. <p>Line 17: the quick brown fox jumps over the lazy dog.</p>
  38. <p>Line 18: the quick brown fox jumps over the lazy dog.</p>
  39. <p>Line 19: the quick brown fox jumps over the lazy dog.</p>
  40. <p>Line 20: the quick brown fox jumps over the lazy dog.</p>
  41. <p>Line 21: the quick brown fox jumps over the lazy dog.</p>
  42. <p>Line 22: the quick brown fox jumps over the lazy dog.</p>
  43. <p>Line 23: the quick brown fox jumps over the lazy dog.</p>
  44. <p>Line 24: the quick brown fox jumps over the lazy dog.</p>
  45. </div>
  46. <div class="after">end of content</div>
  47. </body>
  48. </html>