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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. position: relative;
  71. }
  72. .bubble-content .bubble-item {
  73. border-radius: 50%;
  74. color: #fff;
  75. font-weight: bold;
  76. font-size: 24px;
  77. text-align: center;
  78. border:3px solid #fff;
  79. line-height: 100px;
  80. width: 100px;
  81. height: 100px;
  82. background-color: red;
  83. }
  84. .bubble-content .bubble-one {
  85. width: 50px;
  86. height: 50px;
  87. line-height: 50px;
  88. position: absolute;
  89. top:50%;
  90. left: 50%;
  91. margin-top: -25px;
  92. margin-left: -25px;
  93. }
  94. .bubble-content .bubble-two {
  95. background-color: #ffd54f;
  96. width: 80px;
  97. height: 80px;
  98. line-height: 80px;
  99. position: absolute;
  100. top:30px;
  101. left:30px;
  102. }
  103. .bubble-content .bubble-three {
  104. width: 100px;
  105. height: 100px;
  106. line-height: 100px;
  107. background-color: #81d4fa;
  108. position: absolute;
  109. top:60px;
  110. left:60px;
  111. }
  112. .bubble-content .bubble-item::after{
  113. content: '';
  114. display: block;
  115. width: 20%;
  116. height: 15%;
  117. background-color: rgba(0, 0, 0, 0.3);
  118. position: absolute;
  119. top: 20%;
  120. left: 20%;
  121. border-radius: 50%;
  122. }
  123. /* .bubble-content .bubble-one:hover{
  124. width: 60px;
  125. height: 60px;
  126. margin-top: -30px;
  127. margin-left: -30px;
  128. line-height: 60px;
  129. } */
  130. .bubble-content .bubble-item:hover{
  131. /* transform 变形 scale 缩放 */
  132. transform: scale(1.5);
  133. z-index: 1000;
  134. }
  135. </style>
  136. </head>
  137. <body>
  138. <!-- 全屏容器 -->
  139. <div class="fullscreen-container"></div>
  140. <!-- 定位气泡容器 -->
  141. <div class="bubble-container">
  142. <div class="text">
  143. <h1>趣味气泡 Position 练习</h1>
  144. <p class="info">任务: 观察并理解气泡的定位方式,鼠标悬停气泡试试看!</p>
  145. <p class="desc">(气泡用 absolute,气泡区用 relative,底部说明条用 fixed)</p>
  146. </div>
  147. <div class="bubble-content">
  148. <div class="bubble-item bubble-one">A</div>
  149. <div class="bubble-item bubble-two">B</div>
  150. <div class="bubble-item bubble-three">C</div>
  151. </div>
  152. </div>
  153. <!-- 底部信息 -->
  154. <div class="bottom-info">本页面用于练习 position: relative / absolute / fixed 及 hover/伪元素效果</div>
  155. </body>
  156. </html>