css轮播图_纯css实现轮播图

首先看效果:

9a1c0aec3c164790974d838b9deca76e.gif

html代码:

    <div class="box">                <input type="radio" name="btn" id="btn1" checked>        <input type="radio" name="btn" id="btn2">        <input type="radio" name="btn"id="btn3">        <input type="radio" name="btn" id="btn4">        <input type="radio" name="btn" id="btn5">        <input type="radio" name="btn" id="btn6">        <input type="radio" name="btn" id="btn7">        <label for="btn1">label>        <label for="btn2">label>        <label for="btn3">label>        <label for="btn4">label>        <label for="btn5">label>        <label for="btn6">label>        <label for="btn7">label>                <ul>            <li><img src="images/1.png" alt="" />li>            <li><img src="images/2.png" alt="" />li>            <li><img src="images/3.png" alt="" />li>            <li><img src="images/4.png" alt="" />li>            <li><img src="images/5.png" alt="" />li>            <li><img src="images/6.png" alt="" />li>            <li><img src="images/7.png" alt="" />li>        ul>    div>    

css代码:

body{    background-color: yellowgreen;    display: flex;    justify-content: center;    align-items: center;    /* vh就是当前屏幕可见高度的1%,也就是说,height:100vh == height:100%;    但是当元素没有内容时候,设置height:100%,该元素不会被撑开,此时高度为0,    但是设置height:100vh,该元素会被撑开屏幕高度一致。 */    height: 100vh;}/*这里用了响应式,即大于320px以上则执行这个代码*/@media screen and (min-width:320px){    .box {        width: 857px;        height: 441px;    }    label{        position: absolute;        width: 20px;        height: 20px;        border-radius: 50% ;        bottom: 20px;        background-color: #fff;        }}/*屏幕小于320px则下面这个代码执行*/@media screen and (max-width:320px){    .box {        width: 514.2px;        height: 167.58px;    }    img{        width: 38%;        height: 100%;    }    label{        position: absolute;        width: 10px;        height: 10px;        border-radius: 50% ;        bottom: 10px;        background-color: #fff;        }}.box{    position: relative;    overflow: hidden;}input {    display: none;}/*设置小圆点*//* label{    position: absolute;    width: 20px;    height: 20px;    border-radius: 50% ;    bottom: 20px;    background-color: #fff;}*//* 属性选择器*/label[for="btn1"]{    left: 35%;}label[for="btn2"] {  left: 40%;}label[for="btn3"] {  left: 45%;}label[for="btn4"] {  left: 50%;}label[for="btn5"] {  left: 55%;}label[for="btn6"] {  left: 60%;}label[for="btn7"] {  left: 65%;}ul{    display: flex;    /*计算图片的总长*/    width: calc(875px*7);    transition: all 0.5s;}ul li{    list-style-type: none;}#btn1:checked  ~ul{    margin-left: 0;}#btn2:checked ~ ul {  margin-left: -857px;}#btn3:checked ~ ul {  margin-left: calc(-857px * 2);}#btn4:checked ~ ul {  margin-left: calc(-857px * 3);}#btn5:checked ~ ul {  margin-left: calc(-857px * 4);}#btn6:checked ~ ul {  margin-left: calc(-857px * 5);}#btn7:checked ~ ul {  margin-left: calc(-857px * 6);}#btn1:checked ~ label[for="btn1"] {  background-color: pink;}#btn2:checked ~ label[for="btn2"] {  background-color: pink;}#btn3:checked ~ label[for="btn3"] {  background-color: pink;}#btn4:checked ~ label[for="btn4"] {  background-color: pink;}#btn5:checked ~ label[for="btn5"] {  background-color: pink;}#btn6:checked ~ label[for="btn6"] {  background-color: pink;}#btn7:checked ~ label[for="btn7"] {  background-color: pink;}

完整代码可在公众号回复1123获得。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值