纯CSS实现轮播图的效果

纯css实现轮播图的效果@TOC

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>轮播图</title>
  </head>
  <body>
    <ul class="slides">
      <input type="radio" id="control-1" name="control" checked />
      <input type="radio" id="control-2" name="control" />
      <input type="radio" id="control-3" name="control" />

      <li class="slide">1</li>
      <li class="slide">2</li>
      <li class="slide">3</li>

      <div class="controls-visible">
        <label for="control-1"></label>
        <label for="control-2"></label>
        <label for="control-3"></label>
      </div>
    </ul>
  </body>
</html>
<style>
  body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
  }
  ul.slides {
    position: relative;
    width: 600px;
    height: 280px;
    list-style: none;
    margin: 0;
    padding: 0;
    background-color: pink;
    overflow: hidden;
  }
  li.slide {
    margin: 0;
    padding: 0;
    width: inherit;
    height: inherit;
    position: absolute;
    top: 0;
    left: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: Helvetica;
    font-size: 120px;
    color: #fff;
    transition: 0.5s transform ease-in-out;
  }
  .slide:nth-of-type(1) {
    background-color: rgb(161, 66, 66);
    left: 0;
  }
  .slide:nth-of-type(2) {
    background-color: rgb(88, 142, 192);
    left: 100%;
  }
  .slide:nth-of-type(3) {
    background-color: rgb(220, 230, 80);
    left: 200%;
  }
  input[type="radio"] {
    position: relative;
    z-index: 100;
    display: none;
  }

  .controls-visible {
    position: absolute;
    width: 100%;
    bottom: 12px;
    text-align: center;
  }
  .controls-visible label {
    display: inline-block;
    width: 10px;
    height: 10px;
    background-color: #fff;
    border-radius: 50%;
    margin: 0 3px;
    border: 2px solid #fff;
  }
  .slides
    input[type="radio"]:nth-of-type(1):checked
    ~ .controls-visible
    label:nth-of-type(1) {
    background-color: #333;
  }
  .slides
    input[type="radio"]:nth-of-type(2):checked
    ~ .controls-visible
    label:nth-of-type(2) {
    background-color: #333;
  }
  .slides
    input[type="radio"]:nth-of-type(3):checked
    ~ .controls-visible
    label:nth-of-type(3) {
    background-color: #333;
  }

  .slides input[type="radio"]:nth-of-type(1):checked ~ .slide {
    transform: translateX(0%);
  }
  .slides input[type="radio"]:nth-of-type(2):checked ~ .slide {
    transform: translateX(-100%);
  }
  .slides input[type="radio"]:nth-of-type(3):checked ~ .slide {
    transform: translateX(-200%);
  }
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值