ttt.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>图片悬停效果展示</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. box-sizing: border-box;
  12. font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  13. }
  14. body {
  15. background: linear-gradient(135deg, #1a2a6c, #b21f1f, #1a2a6c);
  16. background-size: 400% 400%;
  17. animation: gradientBG 15s ease infinite;
  18. min-height: 100vh;
  19. display: flex;
  20. justify-content: center;
  21. align-items: center;
  22. padding: 40px 20px;
  23. color: #fff;
  24. }
  25. @keyframes gradientBG {
  26. 0% {
  27. background-position: 0% 50%;
  28. }
  29. 50% {
  30. background-position: 100% 50%;
  31. }
  32. 100% {
  33. background-position: 0% 50%;
  34. }
  35. }
  36. .container {
  37. max-width: 1200px;
  38. width: 100%;
  39. }
  40. header {
  41. text-align: center;
  42. margin-bottom: 50px;
  43. }
  44. h1 {
  45. font-size: 3.2rem;
  46. margin-bottom: 15px;
  47. text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  48. letter-spacing: 1px;
  49. }
  50. .subtitle {
  51. font-size: 1.2rem;
  52. opacity: 0.9;
  53. max-width: 700px;
  54. margin: 0 auto;
  55. line-height: 1.6;
  56. }
  57. .gallery {
  58. display: grid;
  59. grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  60. gap: 30px;
  61. }
  62. .card {
  63. background: rgba(255, 255, 255, 0.1);
  64. border-radius: 15px;
  65. overflow: hidden;
  66. box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  67. transition: transform 0.4s ease;
  68. height: 300px;
  69. position: relative;
  70. }
  71. .card:hover {
  72. transform: translateY(-10px);
  73. }
  74. .image-container {
  75. width: 100%;
  76. height: 100%;
  77. position: relative;
  78. overflow: hidden;
  79. }
  80. .image-container img {
  81. width: 100%;
  82. height: 100%;
  83. object-fit: cover;
  84. transition: all 0.5s ease;
  85. }
  86. .effect-title {
  87. position: absolute;
  88. bottom: 20px;
  89. left: 20px;
  90. font-size: 1.5rem;
  91. font-weight: 600;
  92. z-index: 2;
  93. text-shadow: 0 2px 5px rgba(0, 0, 0, 0.8);
  94. transition: all 0.4s ease;
  95. }
  96. /* 效果1: 缩放 */
  97. .scale:hover img {
  98. transform: scale(1.1);
  99. }
  100. /* 效果2: 旋转 */
  101. .rotate:hover img {
  102. transform: scale(1.1) rotate(5deg);
  103. }
  104. /* 效果3: 灰度效果 */
  105. .grayscale img {
  106. filter: grayscale(70%);
  107. }
  108. .grayscale:hover img {
  109. filter: grayscale(0%);
  110. transform: scale(1.05);
  111. }
  112. /* 效果4: 文字叠加 */
  113. .overlay-text {
  114. position: absolute;
  115. top: 0;
  116. left: 0;
  117. width: 100%;
  118. height: 100%;
  119. background: rgba(0, 0, 0, 0.7);
  120. display: flex;
  121. flex-direction: column;
  122. justify-content: center;
  123. align-items: center;
  124. padding: 20px;
  125. opacity: 0;
  126. transition: opacity 0.5s ease;
  127. }
  128. .overlay-text h3 {
  129. font-size: 1.8rem;
  130. margin-bottom: 15px;
  131. text-align: center;
  132. }
  133. .overlay-text p {
  134. text-align: center;
  135. line-height: 1.6;
  136. max-width: 80%;
  137. }
  138. .text-overlay:hover .overlay-text {
  139. opacity: 1;
  140. }
  141. .text-overlay:hover img {
  142. transform: scale(1.1);
  143. }
  144. /* 效果5: 模糊效果 */
  145. .blur:hover img {
  146. filter: blur(3px);
  147. transform: scale(1.1);
  148. }
  149. /* 效果6: 边框效果 */
  150. .border-effect {
  151. position: relative;
  152. }
  153. .border-effect::before {
  154. content: "";
  155. position: absolute;
  156. top: 20px;
  157. left: 20px;
  158. right: 20px;
  159. bottom: 20px;
  160. border: 3px solid rgba(255, 255, 255, 0.6);
  161. z-index: 2;
  162. opacity: 0;
  163. transform: scale(0.8);
  164. transition: all 0.5s ease;
  165. }
  166. .border-effect:hover::before {
  167. opacity: 1;
  168. transform: scale(1);
  169. }
  170. .border-effect:hover img {
  171. transform: scale(1.05);
  172. }
  173. .border-effect:hover .effect-title {
  174. transform: translateY(-30px);
  175. }
  176. /* 响应式调整 */
  177. @media (max-width: 768px) {
  178. .gallery {
  179. grid-template-columns: 1fr;
  180. }
  181. h1 {
  182. font-size: 2.5rem;
  183. }
  184. }
  185. </style>
  186. </head>
  187. <body>
  188. <div class="container">
  189. <header>
  190. <h1>图片悬停效果展示</h1>
  191. <p class="subtitle">探索多种CSS实现的鼠标悬停效果。将鼠标悬停在图片上查看各种交互效果。</p>
  192. </header>
  193. <div class="gallery">
  194. <!-- 效果1: 缩放 -->
  195. <div class="card scale">
  196. <div class="image-container">
  197. <img src="https://images.unsplash.com/photo-1501854140801-50d01698950b?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1200&q=80"
  198. alt="自然风景">
  199. <div class="effect-title">缩放效果</div>
  200. </div>
  201. </div>
  202. <!-- 效果2: 旋转 -->
  203. <div class="card rotate">
  204. <div class="image-container">
  205. <img src="https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1200&q=80"
  206. alt="山脉">
  207. <div class="effect-title">旋转效果</div>
  208. </div>
  209. </div>
  210. <!-- 效果3: 灰度效果 -->
  211. <div class="card grayscale">
  212. <div class="image-container">
  213. <img src="https://images.unsplash.com/photo-1469474968028-56623f02e42e?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1200&q=80"
  214. alt="沙漠">
  215. <div class="effect-title">灰度效果</div>
  216. </div>
  217. </div>
  218. <!-- 效果4: 文字叠加 -->
  219. <div class="card text-overlay">
  220. <div class="image-container">
  221. <img src="https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1200&q=80"
  222. alt="森林">
  223. <div class="overlay-text">
  224. <h3>悬停时显示文字</h3>
  225. <p>这是一个在悬停时显示文字叠加层的效果示例</p>
  226. </div>
  227. <div class="effect-title">文字叠加</div>
  228. </div>
  229. </div>
  230. <!-- 效果5: 模糊效果 -->
  231. <div class="card blur">
  232. <div class="image-container">
  233. <img src="https://images.unsplash.com/photo-1441974231531-c6227db76b6e?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1200&q=80"
  234. alt="迷雾森林">
  235. <div class="effect-title">模糊效果</div>
  236. </div>
  237. </div>
  238. <!-- 效果6: 边框效果 -->
  239. <div class="card border-effect">
  240. <div class="image-container">
  241. <img src="https://images.unsplash.com/photo-1506260408121-e353d10b87c7?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1200&q=80"
  242. alt="秋季森林">
  243. <div class="effect-title">边框效果</div>
  244. </div>
  245. </div>
  246. </div>
  247. </div>
  248. </body>
  249. </html>