html实现开关,纯css实现开关、轮播

23000824210701.gif

css样式:/* 基本样式 */

* {

margin: 0px;

padding: 0px;

}

ul,

li {

list-style: none;

}

img {

width: 100%;

display: block;

}

input {

display: none;

}

label {

display: inline-block;

width: 10px;

height: 10px;

border: #fff 3px solid;

}

#main {

margin:10% auto;

width: 700px;

height: 380px;

overflow: hidden;

position: relative;

}

#btn {

position: absolute;

bottom: 15px;

z-index: 5;

left: 50%;

transform: translateX(-50%);

cursor: pointer;

}

ul {

width: 2800px;

position: absolute;

z-index: 1;

transition: 1s

}

li {

float: left;

width: 700px;

}

/* 实现点击轮播 */

/* 按钮变色 */

input#one:checked~#btn label:first-child {

background-color: #000000;

}

input#two:checked~#btn label:nth-child(2) {

background-color: #000000;

}

input#three:checked~#btn label:nth-child(3) {

background-color: #000000;

}

input#four:checked~#btn label:nth-child(4) {

background-color: #000000;

}

/* 换图 */

input#one:checked~ul {

left: 0%;

}

input#two:checked~ul {

left: -100%;

}

input#three:checked~ul {

left: -200%;

}

input#four:checked~ul {

left: -300%;

}

html:

  • 1.jpg
  • 2.jpg
  • 3.jpg
  • 4.jpg

实现思路:

核心:“:checked 选择器匹配每个已被选中的 input 元素(只用于单选按钮和复选框)。”

然后input绑定label for联动,input放在外层父元素里面最上面,就是为了能通过css选择器选中ul标签,然后通过点击label实现单选框的选中状态,

然后用:checked来选择ul的左偏移实现轮播效果,当然,给ul标签加点过渡时间就有过渡动画了。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值