[css3] 小案例---动画版轮播图(屏幕宽度)

方法一

animation: donghau 5s steps(5) infinite;
margin-left: -500%;

<!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>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        .box{
            width: 100%;
            height: 400px;
            background-color: burlywood;
            overflow: hidden;
        }
        .box>.bigbox{
            width: 500%;
            height: 400px;
            background-color: rgb(180, 84, 84);
            animation: donghau 5s steps(5) infinite; 
        }
        .box>.bigbox>div{
            width: 20%;
            height: 400px;
            font-size: 100px;
            font-weight: bold;
            text-align: center;
            line-height: 400px;
            float: left;
        }
        .box>.bigbox>div:nth-child(1){
            background-color: rgb(210, 247, 199);
        }
        .box>.bigbox>div:nth-child(2){
            background-color: rgb(248, 195, 195);
        }
        .box>.bigbox>div:nth-child(3){
            background-color: rgb(198, 245, 239);
        }
        .box>.bigbox>div:nth-child(4){
            background-color: rgb(216, 201, 235);
        }
        .box>.bigbox>div:nth-child(5){
            background-color: rgb(243, 209, 220);
        }
        

        @keyframes donghau{
            0%{
                margin-left: 0;
            }
            100%{
                margin-left: -500%; 
                
            }
        }
    </style>
</head>
<body>
    <!-- 盒子:观看轮播图区域切换的窗口 -->
    <div class="box">
        <!-- 用来进行移动的 -->
        <div class="bigbox">
            <div>1</div>
            <div>2</div>
            <div>3</div>
            <div>4</div>
            <div>5</div>
        </div>
    </div>
</body>
</html>

方法二

animation: donghau 5s steps(5) infinite;
transform: translate(-100%);

<!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>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        .box{
            width: 100%;
            height: 400px;
            background-color: burlywood;
            overflow: hidden;
        }
        .box>.bigbox{
            width: 500%;
            height: 400px;
            background-color: rgb(180, 84, 84);
            animation: donghau 5s steps(5) infinite; 
        }
        .box>.bigbox>div{
            width: 20%;
            height: 400px;
            font-size: 100px;
            font-weight: bold;
            text-align: center;
            line-height: 400px;
            float: left;
        }
        .box>.bigbox>div:nth-child(1){
            background-color: rgb(210, 247, 199);
        }
        .box>.bigbox>div:nth-child(2){
            background-color: rgb(248, 195, 195);
        }
        .box>.bigbox>div:nth-child(3){
            background-color: rgb(198, 245, 239);
        }
        .box>.bigbox>div:nth-child(4){
            background-color: rgb(216, 201, 235);
        }
        .box>.bigbox>div:nth-child(5){
            background-color: rgb(243, 209, 220);
        }
        

        @keyframes donghau{
            0%{
                margin-left: 0;
            }
            100%{
                
                transform: translate(-100%);
            }
        }
    </style>
</head>
<body>
    <!-- 盒子:观看轮播图区域切换的窗口 -->
    <div class="box">
        <!-- 用来进行移动的 -->
        <div class="bigbox">
            <div>1</div>
            <div>2</div>
            <div>3</div>
            <div>4</div>
            <div>5</div>
        </div>
    </div>
</body>
</html>

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值