练习10_定位气泡.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. /* css reset */
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. }
  13. .fullscreen-container {
  14. /* height: 100vh;
  15. width: 100vw; */
  16. background-color: #f0f4c3;
  17. position: fixed;
  18. top: 0;
  19. left: 0;
  20. right: 0;
  21. bottom: 0;
  22. }
  23. .bubble-container{
  24. width: 500px;
  25. height: 600px;
  26. background-color: #fff;
  27. z-index: 1000;
  28. position: fixed;
  29. top: 50%;
  30. left: 50%;
  31. margin-top: -300px;
  32. margin-left: -250px;
  33. padding: 20px;
  34. box-sizing: border-box;
  35. }
  36. .bottom-info{
  37. /* 如果块元素定位后fixed 和 absolute宽度会变成内容的宽*/
  38. position: fixed;
  39. bottom: 0;
  40. left: 0;
  41. height: 50px;
  42. width: 100%;
  43. text-align: center;
  44. line-height: 50px;
  45. color: #b28704;
  46. background-color: #fffde7;
  47. }
  48. .bubble-container .text{
  49. text-align: center;
  50. }
  51. .bubble-container .text h1{
  52. color: #689f38;
  53. margin:20px 0;
  54. }
  55. .bubble-container .text .info {
  56. width: 300px;
  57. margin: 0 auto;
  58. }
  59. .bubble-container .text .desc {
  60. font-size: 12px;
  61. color: #999;
  62. margin-top: 20px;
  63. }
  64. .bubble-container .bubble-content{
  65. width: 100%;
  66. height: 380px;
  67. background-color:#b2dfdb;
  68. margin-top: 20px;
  69. border-radius: 20px;
  70. }
  71. </style>
  72. </head>
  73. <body>
  74. <!-- 全屏容器 -->
  75. <div class="fullscreen-container"></div>
  76. <!-- 定位气泡容器 -->
  77. <div class="bubble-container">
  78. <div class="text">
  79. <h1>趣味气泡 Position 练习</h1>
  80. <p class="info">任务: 观察并理解气泡的定位方式,鼠标悬停气泡试试看!</p>
  81. <p class="desc">(气泡用 absolute,气泡区用 relative,底部说明条用 fixed)</p>
  82. </div>
  83. <div class="bubble-content"></div>
  84. </div>
  85. <!-- 底部信息 -->
  86. <div class="bottom-info">本页面用于练习 position: relative / absolute / fixed 及 hover/伪元素效果</div>
  87. </body>
  88. </html>