| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>图片悬停效果展示</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- box-sizing: border-box;
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
- }
- body {
- background: linear-gradient(135deg, #1a2a6c, #b21f1f, #1a2a6c);
- background-size: 400% 400%;
- animation: gradientBG 15s ease infinite;
- min-height: 100vh;
- display: flex;
- justify-content: center;
- align-items: center;
- padding: 40px 20px;
- color: #fff;
- }
- @keyframes gradientBG {
- 0% {
- background-position: 0% 50%;
- }
- 50% {
- background-position: 100% 50%;
- }
- 100% {
- background-position: 0% 50%;
- }
- }
- .container {
- max-width: 1200px;
- width: 100%;
- }
- header {
- text-align: center;
- margin-bottom: 50px;
- }
- h1 {
- font-size: 3.2rem;
- margin-bottom: 15px;
- text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
- letter-spacing: 1px;
- }
- .subtitle {
- font-size: 1.2rem;
- opacity: 0.9;
- max-width: 700px;
- margin: 0 auto;
- line-height: 1.6;
- }
- .gallery {
- display: grid;
- grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
- gap: 30px;
- }
- .card {
- background: rgba(255, 255, 255, 0.1);
- border-radius: 15px;
- overflow: hidden;
- box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
- transition: transform 0.4s ease;
- height: 300px;
- position: relative;
- }
- .card:hover {
- transform: translateY(-10px);
- }
- .image-container {
- width: 100%;
- height: 100%;
- position: relative;
- overflow: hidden;
- }
- .image-container img {
- width: 100%;
- height: 100%;
- object-fit: cover;
- transition: all 0.5s ease;
- }
- .effect-title {
- position: absolute;
- bottom: 20px;
- left: 20px;
- font-size: 1.5rem;
- font-weight: 600;
- z-index: 2;
- text-shadow: 0 2px 5px rgba(0, 0, 0, 0.8);
- transition: all 0.4s ease;
- }
- /* 效果1: 缩放 */
- .scale:hover img {
- transform: scale(1.1);
- }
- /* 效果2: 旋转 */
- .rotate:hover img {
- transform: scale(1.1) rotate(5deg);
- }
- /* 效果3: 灰度效果 */
- .grayscale img {
- filter: grayscale(70%);
- }
- .grayscale:hover img {
- filter: grayscale(0%);
- transform: scale(1.05);
- }
- /* 效果4: 文字叠加 */
- .overlay-text {
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- background: rgba(0, 0, 0, 0.7);
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- padding: 20px;
- opacity: 0;
- transition: opacity 0.5s ease;
- }
- .overlay-text h3 {
- font-size: 1.8rem;
- margin-bottom: 15px;
- text-align: center;
- }
- .overlay-text p {
- text-align: center;
- line-height: 1.6;
- max-width: 80%;
- }
- .text-overlay:hover .overlay-text {
- opacity: 1;
- }
- .text-overlay:hover img {
- transform: scale(1.1);
- }
- /* 效果5: 模糊效果 */
- .blur:hover img {
- filter: blur(3px);
- transform: scale(1.1);
- }
- /* 效果6: 边框效果 */
- .border-effect {
- position: relative;
- }
- .border-effect::before {
- content: "";
- position: absolute;
- top: 20px;
- left: 20px;
- right: 20px;
- bottom: 20px;
- border: 3px solid rgba(255, 255, 255, 0.6);
- z-index: 2;
- opacity: 0;
- transform: scale(0.8);
- transition: all 0.5s ease;
- }
- .border-effect:hover::before {
- opacity: 1;
- transform: scale(1);
- }
- .border-effect:hover img {
- transform: scale(1.05);
- }
- .border-effect:hover .effect-title {
- transform: translateY(-30px);
- }
- /* 响应式调整 */
- @media (max-width: 768px) {
- .gallery {
- grid-template-columns: 1fr;
- }
- h1 {
- font-size: 2.5rem;
- }
- }
- </style>
- </head>
- <body>
- <div class="container">
- <header>
- <h1>图片悬停效果展示</h1>
- <p class="subtitle">探索多种CSS实现的鼠标悬停效果。将鼠标悬停在图片上查看各种交互效果。</p>
- </header>
- <div class="gallery">
- <!-- 效果1: 缩放 -->
- <div class="card scale">
- <div class="image-container">
- <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"
- alt="自然风景">
- <div class="effect-title">缩放效果</div>
- </div>
- </div>
- <!-- 效果2: 旋转 -->
- <div class="card rotate">
- <div class="image-container">
- <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"
- alt="山脉">
- <div class="effect-title">旋转效果</div>
- </div>
- </div>
- <!-- 效果3: 灰度效果 -->
- <div class="card grayscale">
- <div class="image-container">
- <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"
- alt="沙漠">
- <div class="effect-title">灰度效果</div>
- </div>
- </div>
- <!-- 效果4: 文字叠加 -->
- <div class="card text-overlay">
- <div class="image-container">
- <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"
- alt="森林">
- <div class="overlay-text">
- <h3>悬停时显示文字</h3>
- <p>这是一个在悬停时显示文字叠加层的效果示例</p>
- </div>
- <div class="effect-title">文字叠加</div>
- </div>
- </div>
- <!-- 效果5: 模糊效果 -->
- <div class="card blur">
- <div class="image-container">
- <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"
- alt="迷雾森林">
- <div class="effect-title">模糊效果</div>
- </div>
- </div>
- <!-- 效果6: 边框效果 -->
- <div class="card border-effect">
- <div class="image-container">
- <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"
- alt="秋季森林">
- <div class="effect-title">边框效果</div>
- </div>
- </div>
- </div>
- </div>
- </body>
- </html>
|