2018-06-07CSS1 分钟 读完 (大约 121 个字)用animation写轮播图代码 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>轮播图</title> <style> * { padding: 0; margin: 0; } a { text-decoration: none; } body { min-width: 1080px; background-color: #f4f4f4; } .banner { width: 1000px; overflow: hidden; margin: 0 auto; } .box>img { float: left; width: 1000px; } .box { width: 5000px; animation: banner 25s infinite 3s; } @keyframes banner { 20% { margin-left: -1000px; } 40% { margin-left: -2000px; } 60% { margin-left: -3000px; } 80% { margin-left: -4000px; } } </style></head><body> <div class="banner"> <div class="box"> <img src="image/4.png" alt=""> <img src="image/5.png" alt=""> <img src="image/2.png" alt=""> <img src="image/3.png" alt=""> <img src="image/1.png" alt=""> </div> </div></body></html> 改进123456789101112131415161718<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title></title> <link rel="stylesheet" href="css/style.css"></head><body> <div class="banner"> <div class="box"> <img src="image/5e52a48c00012a6418720764.jpg" alt=""> <img src="image/5e52a74200016f6218720764.jpg" alt=""> <img src="image/5e59d4c600017cc318720764.jpg" alt=""> <img src="image/5e5f7aea0001a36618720764.jpg" alt=""> </div> </div></body></html> 12345678910111213141516171819202122232425262728293031323334353637383940414243* { padding: 0; margin: 0;}a { text-decoration: none;}body { min-width: 1080px; background-color: #f4f4f4;}.banner { width: 1000px; height: 408px; /* border: 1px red solid; */ overflow: hidden; margin: 0 auto;}.banner>div>img { width: 1000px; height: 408px; float: left;}.box { width: 4000px; animation: banner 16s 2s infinite;}@keyframes banner { 25% { margin-left: -1000px; } 50% { margin-left: -2000px; } 75% { margin-left: -3000px; }}