HTML 代码: <div class="slider"> <ul class="slider-list"> <li><img src="img1.jpg"></li> <li><img src="img2.jpg"></li> <li><img src="img3.jpg"></li> <li><img src="img4.jpg"></li> </ul> <div class="slider-dot"> <button class="dot active"></button> <button class="dot"></button> <button class="dot"></button> <button class="dot"></button> </div> <button class="slider-prev"></button> <button class="slider-next"></button> </div> CSS 代码: .slider { position: relative; width: 100%; height: 300px; overflow: hidden; } .slider-list { position: absolute; left: 0; width: 400%; height: 100%; list-style: none; margin: 0; padding: 0; transition: all 0.5s; } .slider-list li { position: relative; float: left; width: 25%; height: 100%; } .slider-list li img { width: 100%; height: 100%; } .slider-dot { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; } .slider-dot .dot { width: 10px; height: 10px; border-radius: 50%; margin: 0 5px; background-color: #ccc; cursor: pointer; } .slider-dot .active { background-color: #000; } .slider-prev, .slider-next { position: absolute; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; border-radius: 50%; background-color: #ccc; border: none; cursor: pointer; } .slider-prev { left: 20px; } .slider-next { right: 20px; }
上面的代码是一个简单的轮播展示的 HTML 和 CSS 代码,其中使用了 div、ul、li、button 等 HTML 标签,需要注意的是,在 CSS 中,需要通过定位和样式来实现图片的切换和按钮的事件,还要加上动画效果,才能达到良好的视觉效果和操作体验。