废话不多说直接上代码 CTRL+C CTRL+V 走就能用了
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS3 自动轮播图</title> <style> body { margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; min-height: 100vh; background-color: #f0f0f0; } .slider { width: 600px; height: 400px; overflow: hidden; } .slides { width: 300%; display: flex; animation: slide-animation 10s infinite; } .slide { width: 33.333%; /* transition: 0.5s; */ } .slide img { width: 100%; height: 100%; } @keyframes slide-animation { 0%, 100% { margin-left: 0; } 20% { margin-left: 0; } 30% { margin-left: -100%; } 50% { margin-left: -100%; } 60% { margin-left: -200%; } 80% { margin-left: -200%; } 90% { margin-left: 0; } } </style> </head> <body> <div class="slider"> <div class="slides"> <div class="slide first"> <img src="./123.png" alt="Slide 1"> </div> <div class="slide"> <img src="./123.png" alt="Slide 2"> </div> <div class="slide"> <img src="./123.png" alt="Slide 1"> </div> </div> </div> </body> </html>