轮播图写法一:定位
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
*{
padding: 0;
margin: 0;
list-style: none;
text-decoration: none;
}
#wrap{
width: 590px;
height: 470px;
margin: 50px auto;
border: 10px red solid;
position: relative;
}
img{
vertical-align: middle;
}
/* .imgs{
} */
.imgs>img{
position: absolute;
}
.imgs>img:nth-child(4){
z-index: 3;
}
.piont{
position: absolute;
left: 30px;
bottom: 20px;
z-index:99;
}
.piont>a{
display: inline-block;
width: 10px;
height: 10px;
border-radius: 50%;
background-color: rgb(243,206,139);
margin: 0 3px;
border: 2px solid transparent;
/* 背景色只到内容区,边框没有背景 */
background-clip: content-box;
}
.piont>a:hover{
background-color: #fff;
border: 2px solid rgb(100,100,109);
}
</style>
</head>
<body>
<!--
手写轮播图两种写法(结合js)
1、float
2、定位方式
-->
<!--3、 swiper插件一种写法 (会引用,会修改即可) -->
<!-- 轮播图 -->
<div id="wrap">
<!-- 图片 -->
<div class="imgs">
<img src="./img/1.jpg" alt="">
<img src="./img/2.jpg" alt="">
<img src="./img/3.jpg" alt="">
<img src="./img/4.jpg" alt="">
<img src="./img/5.jpg" alt="">
</div>
<!-- 小圆点 -->
<div class="piont">
<a href="#"></a>
<a href="#"></a>
<a href="#"></a>
<a href="#"></a>
<a href="#"></a>
</div>
</div>
</body>
</html>
轮播图写法二:float
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<!-- 拓展:利用锚点功能或者其他方式,纯css实现图片切换 -->
<style>
*{
padding: 0;
margin: 0;
list-style: none;
text-decoration: none;
}
#wrap{
width: 590px;
height: 470px;
margin: 50px auto;
/* border: 10px red solid; */
overflow: hidden;
position: relative;
}
img{
vertical-align: middle;
}
.imgs{
width: 2950px;
}
.imgs>img{
float: left;
}
.piont{
position: absolute;
left: 30px;
bottom: 20px;
}
.piont>a{
display: inline-block;
width: 10px;
height: 10px;
border-radius: 50%;
background-color: rgb(243,206,139);
margin: 0 3px;
border: 2px solid transparent;
/* 背景色只到内容区,边框没有背景 */
background-clip: content-box;
}
.piont>a:hover{
background-color: #fff;
border: 2px solid rgb(100,100,109);
}
</style>
</head>
<body>
<!--
手写轮播图两种写法(结合js)
1、float
2、定位方式
-->
<!--3、swiper插件一种写法 (会引用,会修改即可) -->
<!-- 轮播图 -->
<div id="wrap">
<!-- 图片 -->
<div class="imgs">
<img src="./img/1.jpg" alt="">
<img src="./img/2.jpg" alt="">
<img src="./img/3.jpg" alt="">
<img src="./img/4.jpg" alt="">
<img src="./img/5.jpg" alt="">
</div>
<!-- 小圆点 -->
<div class="piont">
<a href="#"></a>
<a href="#"></a>
<a href="#"></a>
<a href="#"></a>
<a href="#"></a>
</div>
<!-- 上一张下一张 -->
<div>
<span></span>
<span></span>
</div>
</div>
</body>
</html>
轮播图写法三:swiper
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<!--swiper官网:
https://www.swiper.com.cn/index.html -->
<!-- 第一步 1引入swiper里面的css文件 -->
<link rel="stylesheet" href="./swiper/swiper-bundle.css" />
<style>
/* 第三步:修改轮播图swiper的大小 (可选) */
.swiper {
width: 590px;
height: 480px;
margin: 50px auto;
}
/*
如果要更改轮播图的样式,
第一种方式可以直接选中对应的类名,进行修改
第二种方式:直接css文件修改(不推荐使用)
*/
.swiper-pagination-bullet{
background-color: turquoise;
width: 20px;
height: 20px;
}
</style>
</head>
<body>
<!-- 第二步:写html的结构 -->
<div class="swiper">
<!-- 图片 -->
<div class="swiper-wrapper">
<div class="swiper-slide">
<img src="./img/1.jpg" alt="" />
</div>
<div class="swiper-slide">
<img src="./img/2.jpg" alt="" />
</div>
<div class="swiper-slide">
<img src="./img/3.jpg" alt="" />
</div>
</div>
<!-- 如果需要分页器 小圆点 -->
<div class="swiper-pagination"></div>
<!-- 如果需要导航按钮 上一张 下一张 -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
<!-- 第一步 2引入对应的js文件 -->
<script src="./swiper/swiper-bundle.js"></script>
<!-- 第四步:初始化swiper -->
<script>
var mySwiper = new Swiper(".swiper", {
// autoplay: {//设置自动切换,可以更改切换时间
// delay: 2000,
// },
loop: true, // 循环模式选项
effect: 'cards',//设置切换的方式
// 如果需要分页器
pagination: {
el: ".swiper-pagination",
clickable :true,//设置小圆点点击切换图片
},
// 如果需要前进后退按钮
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
});
</script>
</body>
</html>