index2.html 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>鼠标穿透示例</title>
  6. <style>
  7. body {
  8. margin: 0;
  9. height: 100vh;
  10. background-color: #f0f0f0;
  11. display: flex;
  12. justify-content: center;
  13. align-items: center;
  14. }
  15. .container {
  16. position: relative;
  17. width: 300px;
  18. height: 300px;
  19. background-color: rgba(0, 150, 255, 0.5); /* 半透明 */
  20. display: flex;
  21. justify-content: center;
  22. align-items: center;
  23. color: white;
  24. font-size: 24px;
  25. text-align: center;
  26. }
  27. .transparent-area {
  28. position: absolute;
  29. top: 20px; /* 设置透明区域的顶部位置 */
  30. left: 20px; /* 设置透明区域的左边位置 */
  31. width: 100px; /* 设置透明区域宽度 */
  32. height: 100px; /* 设置透明区域高度 */
  33. background-color: transparent; /* 透明度 */
  34. pointer-events: none; /* 允许鼠标事件穿透 */
  35. }
  36. .underlying {
  37. position: absolute;
  38. width: 100px;
  39. height: 100px;
  40. background-color: orange;
  41. top: 100px;
  42. left: 100px;
  43. z-index: -1; /* 确保位于底层 */
  44. }
  45. </style>
  46. </head>
  47. <body>
  48. <div class="container">
  49. <div>鼠标穿透示例</div>
  50. <div class="transparent-area"></div> <!-- 允许鼠标穿透的区域 -->
  51. <div class="underlying"></div> <!-- 背后的元素 -->
  52. </div>
  53. </body>
  54. </html>