使用css实现简易轮播图效果

一、首先可以给盒子添加浮动属性或者设置flex使其在一行内显示
然后在父盒子设置overflow:hidden;超出影藏把多于图片藏起来。
二、利用a标签使用锚点连接来实现跳转效果
三、给父盒子添加scorll-behavior:smooth; 这样可以使跳转变慢一点来增加用户体验。

参考代码

<style>
        .con {
            position: relative;
            width: 520px;
            height: 280px;
            margin: 100px auto;
        }
        
        .con .imgs {
            display: flex;
            overflow: hidden;
            width: 100%;
            height: 100%;
            scroll-behavior: smooth;
        }
        
        .btn {
            position: absolute;
            bottom: 20px;
            right: 20px;
        }
        
        .btn a {
            display: inline-block;
            width: 20px;
            height: 20px;
            background: rgba(00, 00, 00, 0.3);
            font-size: 12px;
            color: #fff;
            text-align: center;
            line-height: 20px;
        }
    </style>
</head>

<body>
    <div class="con">
        <div class="imgs">
            <img src="images/1.jpg" alt="" id="box1">
            <img src="images/2.jpg" alt="" id="box2">
            <img src="images/3.jpg" alt="" id="box3">
        </div>
        <div class="btn">
            <a href="#box1">1</a>
            <a href="#box2">2</a>
            <a href="#box3">3</a>
        </div>
    </div>
</body>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值