练习12_定位练习.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. body{
  9. background-color: #f0f4c3;
  10. }
  11. .content{
  12. width: 600px;
  13. height: 600px;
  14. background-color: #fff;
  15. position: absolute;
  16. top: 50%;
  17. left: 50%;
  18. margin-top: -300px;
  19. margin-left: -300px;
  20. border-radius: 20px;
  21. box-shadow: 0 0 10px rgba(0,0,0,0.5);
  22. padding-top: 20px;
  23. }
  24. .content-info h1{
  25. text-align: center;
  26. color: #689f38;
  27. }
  28. .content-info .info-center{
  29. width: 300px;
  30. margin: 0 auto;
  31. text-align: center;
  32. }
  33. .content-info .info-bottom{
  34. text-align: center;
  35. color: #999;
  36. font-size: 12px;
  37. }
  38. .content-bubble{
  39. width: 500px;
  40. height: 350px;
  41. background-color: #b2dfdb;
  42. margin:0 auto;
  43. border-radius: 20px;
  44. position: relative;
  45. }
  46. .bubble-item{
  47. width: 100px;
  48. height: 100px;
  49. background-color: #81d4fa;
  50. border-radius: 50%;
  51. border:3px solid #fff;
  52. position: absolute;
  53. top:50%;
  54. margin-top: -50px;
  55. left:30px;
  56. text-align: center;
  57. line-height: 100px;
  58. }
  59. .bubble-item span{
  60. color: #fff;
  61. }
  62. .bubble-item::after{
  63. content: "";
  64. display: block;
  65. width: 30%;
  66. height: 20%;
  67. background-color: #fff;
  68. position: absolute;
  69. top:20%;
  70. left: 20%;
  71. border-radius: 50%;
  72. opacity: 0.3;
  73. }
  74. .bubble-item:nth-child(2){
  75. left: 23%;
  76. top: 40%;
  77. background-color: #ffd54f;
  78. width: 80px;
  79. height: 80px;
  80. line-height: 80px;
  81. }
  82. .bubble-item:nth-child(3){
  83. left: 53%;
  84. top: 60%;
  85. background-color: red;
  86. width: 60px;
  87. height: 60px;
  88. line-height: 60px;
  89. }
  90. .bubble-item:hover{
  91. cursor: pointer;
  92. z-index: 1;
  93. /* 控制元素缩放 */
  94. transform: scale(1.2);
  95. }
  96. /* .bubble-item:first-child:hover{
  97. width: 108px;
  98. height: 108px;
  99. } */
  100. .footer{
  101. background-color: #fffde7;
  102. color: #b28704;
  103. /* 脱离文档流后的元素宽度跟内容撑开 */
  104. position: fixed;
  105. left: 0;
  106. bottom: 0;
  107. width: 100%;
  108. text-align: center;
  109. }
  110. </style>
  111. </head>
  112. <body>
  113. <div class="container">
  114. <div class="content">
  115. <div class="content-info">
  116. <h1>趣味气泡 Position 练习</h1>
  117. <p class="info-center"><strong>任务:</strong> 观察并理解气泡的定位方式,鼠标悬停气泡试试看!</p>
  118. <p class="info-bottom">(气泡用 absolute,气泡区用 relative,底部说明条用 fixed)</p>
  119. </div>
  120. <div class="content-bubble">
  121. <div class="bubble-item">
  122. <span>A</span>
  123. </div>
  124. <div class="bubble-item">
  125. <span>B</span>
  126. </div>
  127. <div class="bubble-item">
  128. <span>C</span>
  129. </div>
  130. </div>
  131. </div>
  132. <div class="footer">
  133. <p>本页面用于练习 position: relative / absolute / fixed 及 hover/伪元素效果</p>
  134. </div>
  135. </div>
  136. </body>
  137. </html>