用HTML+CSS手写轮播

CSS部分

* {
margin: 0;
padding: 0;
}
body {
background-color: #ccc;
}
.slide {
position: relative;
margin: 100px auto;
width: 800px;
height: 500px;
text-align: center;
font-family: Arial;
color: #fff;
overflow: hidden;
}
.slide ul {
margin: 10px 0;
padding: 0;
width: calc(800px * 3);
transition: all .5s;
}
.slide li {
float: left;
width: 800px;
height: 500px;
list-style: none;
line-height: 500px;
font-size: 50px;
}
.slide li:nth-child(1) {
background-color: #9fa8ef;
}
.slide li:nth-child(2) {
background-color: #ef9fb1;
}
.slide li:nth-child(3) {
background-color: #9fefc3;
}
.slide input[name="button"] {
display: none;
}
.slide label[for^="button"] {
position: absolute;
top: 450px;
width: 20px;
height: 20px;
margin: 0 10px;
line-height: 20px;
color: #fff;
background-color: #fff;
/* 鼠标移入变成抓手 */
cursor: pointer;
/* 圆角 */
border-radius: 50%;
/* 延迟时间 */
transition: .3s;
}
.slide label[for="button1"] {
left: 40%;
}
.slide label[for="button2"] {
left: 45%;
}
.slide label[for="button3"] {
left: 50%;
}
#button1:checked~ul {
margin-left: 0;
}

#button2:checked~ul {
margin-left: -800px;
}
#button3:checked~ul {
margin-left: -1600px;

#button1:checked~label[for="button1"] {
background: rgb(255, 80, 0);
}
#button2:checked~label[for="button2"] {
background: rgb(255, 80, 0);
}
#button3:checked~label[for="button3"] {
background: rgb(255, 80, 0);
}

HTML部分

<div class="slide">
    <!-- 第一个页面 -->
    <input type="radio" name="button" value="0" id="button1" checked hidden>
    <!-- 小圆点 -->
    <label for="button1"></label>

    <!-- 第二个页面 -->
    <input type="radio" name="button" value="1" id="button2" hidden>
    <!-- 小圆点 -->
    <label for="button2"></label>

    <!-- 第三个页面 -->
    <input type="radio" name="button" value="1" id="button3" hidden>
    <!-- 小圆点 -->
    <label for="button3"></label>


    <ul>
        <li>one</li>
        <li>two</li>
        <li>three</li>
    </ul>
</div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值