开发中实用CSS干货总结(三)CSS伪元素实现多步骤进度条

之前做一个收集用户信息的表单页面需要使用进度条显示用户目前填写到了第几步,不得不说CSS3伪类真的很好用,加上CSS动画加载的效果,不需要js代码就可以实现,进度条是灰色还是亮色通过active类名控制,两个icon的是合成的CSS Sprite图片通过坐标位置显示,背景图下载链接:(https://upload-images.jianshu.io/upload_images/13079544-9af1c6bf06398c8a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

下面是效果图:

 
 
13079544-af10c26e23023c99.gif
 
 

代码如下:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        .progress-bar{
            display: -webkit-box;
            display: -ms-flexbox;
            display: -webkit-flex;
            display: flex;
            margin: 100px auto;
            width: 500px;
        }
        .progress-bar li{
            position: relative;
            text-align: center;
            font-size: 0;
        }
       .progress-bar li .i-icon{
            position: relative;
            display: inline-block;
            width: 27px;
            height: 26px;
            background-image: url("all-icon.png");
            background-size: 54px 26px;
            background-position: 0 0;
        }
        .progress-bar li.active .i-icon {
            background-position: -27px 0;
        }
        .progress-bar li:not(:first-child){
            margin-left: 235px;
        }
        .progress-bar li:first-child .i-icon:after{
            position: absolute;
            top: 10px;
            left:27px;
            content: '';
            width: 496px;
            height: 7px;
            background-color: #dedede;
            z-index: 0;
        }
        .progress-bar li:not(:first-child) .i-icon:after{
            position: absolute;
            top: 10px;
            left: -236px;
            content: '';
            width: 236px;
            height: 7px;
            background-color: #dedede;
            z-index: 1;
        }
        .progress-bar li:not(:first-child).active .i-icon:after{
            background-color: #457bff;
            animation:annimate 2s;
            -webkit-animation:annimate 2s;
        }
        .progress-bar li span{
            position: absolute;
            display: inline-block;
            width: 60px;
            left: -16px;
            bottom: -20px;
            font-size: 14px;
            color: #959595;
        }
        .progress-bar li.active span{
            color: #457bff;
        }
        @keyframes annimate
        {
            from {
                width: 0;
            }
            to {
                width: 236px;
            }
        }
        /* Safari and Chrome */
        @-webkit-keyframes annimate
        {
            from {
                width: 0;
            }
            to {
                width: 236px;
            }
        }
    </style>
</head>
<body>
<ul class="progress-bar">
    <li class="active">
        <i class="i-icon"></i>
        <span>第一步</span>
    </li>
    <li class="active">
        <i class="i-icon"></i>
        <span>第二步</span>
    </li>
    <li>
        <i class="i-icon"></i>
        <span>第三步</span>
    </li>
</ul>
</body>
</html>

原文作者技术博客:https://www.jianshu.com/u/ac4daaeecdfe
95后前端妹子一枚,爱阅读,爱交友,将工作中遇到的问题记录在这里,希望给每一个看到的你能带来一点帮助。
欢迎留言交流。

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值