html+css實現(xiàn)輪播圖
1垃僚、利用a標簽的錨點屬性來實現(xiàn)届吁。
2错妖、給對應的圖片盒子設置ID屬性值。
3疚沐、將圖片盒子的ID屬性值加入對應的a標簽中的href屬性暂氯。
4、圖片盒子加浮動或者flex讓其在一行內顯示亮蛔。
5痴施、父盒子添加overflow:hidden;屬性讓超出的圖片隱藏。
注意:圖片與a標簽在同一個父級元素下不同的元素中
代碼示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
#wrap{
width: 600px;
height: 400px;
border: 1px solid #000;
margin: 100px auto;
position: relative;
}
.imgBox{
width: 600px;
height: 400px;
overflow: hidden;
}
img{
width: 600px;
height: 400px;
}
.btnBox{
width: 150px;
height: 30px;
background: rgba(00, 00,00, 0.5) ;
position: absolute;
right: 10px;
bottom: 10px;
}
a{
float: left;
width: 30px;
height: 30px;
color: #fff;
text-align: center;
line-height: 30px;
text-decoration: none
}
</style>
</head>
<body>
<div id="wrap">
<!-- 圖片 -->
<div class="imgBox">
<img src="" alt="" id="img1">
<img src="" alt="" id="img2">
<img src="" alt="" id="img3">
<img src="" alt="" id="img4">
<img src="" alt="" id="img5">
</div>
<!-- 按鈕 -->
<div class="btnBox">
<a href="#img1">1</a>
<a href="#img2">2</a>
<a href="#img3">3</a>
<a href="#img4">4</a>
<a href="#img5">5</a>
</div>
</div>
</body>
</html>