微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

html中图片轮播css代码

HTML中的图片轮播是网页设计中常用的功能之一,它可以让网页更加生动和动态。CSS是控制HTML样式的强大语言,当它和HTML的图片轮播代码结合使用,就可以实现精美的图片轮播效果

/*CSS样式*/
.slideshow-container {
  max-width: 800px;
  position: relative;
  margin: auto;
}

.mySlides {
   display: none;
}
.prev,.next {
   position: absolute;
   top: 50%;
   width: auto;
   padding: 16px;
   margin-top: -22px;
   color: white;
   font-weight: bold;
   font-size: 18px;
   transition: 0.6s ease;
   border-radius: 0 3px 3px 0;
   cursor: pointer;
}

.next {
   right: 0;
   border-radius: 3px 0 0 3px;
}

.prev:hover,.next:hover {
   background-color: rgba(0,0.8);
}

.text {
   color: #f2f2f2;
   font-size: 15px;
   padding: 8px 12px;
   position: absolute;
   bottom: 8px;
   width: 100%;
   text-align: center;
}

.numbertext {
   color: #f2f2f2;
   font-size: 12px;
   padding: 8px 12px;
   position: absolute;
   top: 0;
}

.dot-container {
   text-align: center;
   padding: 20px;
   background: #ddd;
}

.dot {
   display: inline-block;
   width: 10px;
   height: 10px;
   margin: 0 2px;
   background-color: #bbb;
   border-radius: 50%;
   cursor: pointer;
   transition: background-color 0.6s ease;
}

.active,.dot:hover {
   background-color: #717171;
}

.fade {
   -webkit-animation-name: fade;
   -webkit-animation-duration: 1.5s;
   animation-name: fade;
   animation-duration: 1.5s;
}

/*图片轮播JavaScript代码*/
var slideIndex = 1;
showSlides(slideIndex);

function plusSlides(n) {
    showSlides(slideIndex += n);
}

function currentSlide(n) {
    showSlides(slideIndex = n);
}

function showSlides(n) {
    var i;
    var slides = document.getElementsByClassName("mySlides");
    var dots = document.getElementsByClassName("dot");
    var captionText = document.getElementById("caption");
    if (n > slides.length) {slideIndex = 1}
    if (n 

html中图片轮播css代码

以上CSS代码控制了轮播图容器的最大宽度、内容居中的位置、按钮和文字的样式、导航圆点的样式等。JavaScript代码中定义的函数控制了轮播图的切换,包括上一张和下一张、当前显示图片和导航圆点的变化。

以上就是HTML中图片轮播的CSS代码,可以根据自己的需求对其进行修改和调整,打造出更加出色的网页效果

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐