使用CSS3实现百叶窗

时间:2023-03-08 18:02:36
 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>使用CSS3实现百叶窗</title>
<meta name="keywords" content="" />
<meta name="description" content="" /> <style>
*{margin:0;padding:0;}
body{}
ul,li{list-style:none;}
#banner{width:800px;height:500px;margin:60px auto;border:3px solid #082323;position:relative; }
#banner .pic li{width:200px;height:500px;float:left;position:relative;overflow:hidden;}
#banner .pic li div{width:200px;height:500px;position:absolute;left:-200px;} #banner .pic li div:nth-child(1){background-image:url("images/1.jpg");}
#banner .pic li div:nth-child(2){background-image:url("images/2.jpg");}
#banner .pic li div:nth-child(3){background-image:url("images/3.jpg");}
#banner .pic li div:nth-child(4){background-image:url("images/4.jpg");} #banner .pic li:nth-child(1) div{background-position:0;}
#banner .pic li:nth-child(2) div{background-position:-200px;}
#banner .pic li:nth-child(3) div{background-position:-400px;}
#banner .pic li:nth-child(4) div{background-position:-600px;} input{display:none;} /*隐藏radio按钮*/
label{display:block;width:20px;height:20px;background:#999;z-index:2;
border-radius:100%;color:#fff;position:absolute;bottom:15px;
text-align:center;line-height:20px;
}
label:nth-child(2) {right:100px;}
label:nth-child(4) {right:70px;}
label:nth-child(6) {right:40px;}
label:nth-child(8) {right:10px;}
input:checked + label{background:#0A7979;} /*+获取紧邻兄弟元素加上背景*/ /*~获取相邻兄弟改变div的位置*/
input#ra1:checked ~ .pic li div:nth-child(1){left:0;transition:0.6s;}
input#ra2:checked ~ .pic li div:nth-child(2){left:0;transition:0.6s;}
input#ra3:checked ~ .pic li div:nth-child(3){left:0;transition:0.6s;}
input#ra4:checked ~ .pic li div:nth-child(4){left:0;transition:0.6s;} </style>
</head>
<body> <div id="banner"> <input type="radio" id="ra1" name="choose" checked><label for="ra1">1</label>
<input type="radio" id="ra2" name="choose"><label for="ra2">2</label>
<input type="radio" id="ra3" name="choose"><label for="ra3">3</label>
<input type="radio" id="ra4" name="choose"><label for="ra4">4</label> <ul class="pic">
<li><div></div><div></div><div></div><div></div></li>
<li><div></div><div></div><div></div><div></div></li>
<li><div></div><div></div><div></div><div></div></li>
<li><div></div><div></div><div></div><div></div></li>
</ul>
</div> </body>
</html>