043-relative-zindex.html 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>043 relative z-index</title>
  6. <style>
  7. html, body { margin: 0; padding: 0; background: #ffffff; 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. .pane { float: left; width: 440px; margin-left: 10px; }
  12. .label { background: #eeeeee; padding: 4px 6px; margin-bottom: 4px; }
  13. .stage { position: relative; width: 260px; height: 220px;
  14. background: #f4f4f4; border: 1px solid #999999; }
  15. .red { position: relative; left: 20px; top: 20px; width: 120px; height: 100px;
  16. background: #cc3333; }
  17. .blue { position: relative; left: 60px; top: -60px; width: 120px; height: 100px;
  18. background: #3366cc; }
  19. .z2 { z-index: 2; }
  20. .z1 { z-index: 1; }
  21. </style>
  22. </head>
  23. <body>
  24. <h1>043 &middot; relative z-index</h1>
  25. <p>A: red has z-index 2, blue has z-index 1, so red wins the overlap. B: the same DOM order without z-index paints blue last.</p>
  26. <div class="pane">
  27. <div class="label">A &middot; z-index: red 2, blue 1</div>
  28. <div class="stage">
  29. <div class="red z2"></div>
  30. <div class="blue z1"></div>
  31. </div>
  32. </div>
  33. <div class="pane">
  34. <div class="label">B &middot; no z-index (DOM order)</div>
  35. <div class="stage">
  36. <div class="red"></div>
  37. <div class="blue"></div>
  38. </div>
  39. </div>
  40. </body>
  41. </html>