纯css实现简单的幻灯效果页面
- input:checked结合label for实现
<!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>纯css实现幻灯效果</title>
<style>
.container{
position: relative;
}
img {
display: none;
width: 100px;
height: 100px;
}
input:checked + img {
display: block;
}
input {
position: absolute;
left: -9999px;
}
label {
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<input id="img1" name="img" type="radio" checked="checked">
<img src="./timg.bmp">
<input id="img2" name="img" type="radio">
<img src="../../favicon.png">
</div>
<div class="link">
<label for="img1">第一张</label>
<label for="img2">第二张</label>
</div>
</body>
</html>
- css3的:target结合锚点实现
<!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>纯css实现幻灯效果</title>
<style>
.container{
position: relative;
height: 100px;
}
img{
position: absolute;
width: 100px;
height: 100px;
z-index: 1;
}
img:first-child,
img:target{
z-index: 2
}
</style>
</head>
<body>
<div class="container">
<img src="./timg.bmp" id="img1">
<img src="../../favicon.png" id="img2">
</div>
<div class="link">
<a href="#img1">第一张</a>
<a href="#img2">第二张</a>
</div>
</body>
</html>