写一个css幻灯片

转载:https://blog.csdn.net/hope_It/article/details/82861754
方法1:使用label

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>纯css实现幻灯效果</title>
    <style>
        .container{
            position: relative;
        }
        img {
            display: none;
            width: 100px;
            height: 100px;
        }
        input:checked + img {
            display: block;
        }
        input {
            position: absolute;
            left: -9999px;
        }
        label {
            cursor: pointer;
        }
  </style>
</head>

<body>
    <div class="container">
        <input id="img1" name="img" type="radio" checked="checked">
        <img src="./img2.jpeg">
        <input id="img2" name="img" type="radio">
        <img src="./img1.jpeg">
    </div>
    <div class="link">
        <label for="img1">第一张</label>
        <label for="img2">第二张</label>
    </div>
</body>

</html>

方法二:使用css动画

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>css3 实现幻灯片效果</title>
    <style type="text/css">
        .huanDengPic {
            width: 600px;
            height: 600px;
            margin: 50px auto 0;
            overflow: hidden;
            box-shadow:  0 0 5px rgba(0,0,0,1);   /*CSS3 box-shadow属性*/
            background-size: cover; 
            background-position: center;
            -webkit-animation-name: "loops"; /*检索或设置对象所应用的动画名称*/
            -webkit-animation-duration: 10s; /*检索或设置对象动画的持续时间*/
            -webkit-animation-iteration-count: infinite;  /*检索或设置对象动画的循环次数,此处的"infinite"为无限循环的意思*/
        }

        @-webkit-keyframes "loops" {  /*动画名称和上面设置的动画名称一样*/
            0% {
                background: url(./img1.jpeg) no-repeat;
            }

            50% {
                background: url(./img2.jpeg) no-repeat;
            }

            100% {
                background: url(./img3.jpg) no-repeat;
            }
        }

    </style>
</head>
<body>
    <div class="huanDengPic"></div>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值