css实现箭头进度条

实现的目标:


源码:
首先写出一个基本的样式:

  • 买家下单
  • 买家付款
  • 发货
  • 买家确认收货
  • .progress-bar li {
        padding: 0px 20px;
        line-height: 40px;
        background: #50abe4;
        display: inline-block;
        color: #fff;
        position: relative;
        width: 180px;
        text-align: center;
    }
    

    接下来使用 :after 伪类画出一个三角形,定位到右边:

    .progress-bar li:after {
        content: '';
        display: block;
        border-top: 20px solid red;  
        border-bottom: 20px solid red;  
        border-left: 20px solid blue;  
        position: absolute;
        right: -20px;
        top: 0;  
    }
    

    然后将after的颜色修改下:

    .progress-bar li:after {
        content: '';
        display: block;
        border-top: 20px solid transparent;
        border-bottom: 20px solid transparent;
        border-left: 20px solid #50abe4;
        position: absolute;
        right: -20px;
        top: 0;
        z-index: 10;
    }
    

    使用 :before 伪类来画出左边的三角形:

    .progress-bar li:before{  
        content: '';  
        display: block;  
        border-top: 20px solid red;  
        border-bottom: 20px solid red;  
        border-left: 20px solid blue;  
        position: absolute;   
        left: 0px;   
        top: 0;  
    } 
    

    然后将before的颜色修改下:

    .progress-bar li:before{  
        content: '';
        display: block;
        border-top: 20px solid transparent;
        border-bottom: 20px solid transparent;
        border-left: 20px solid #fff;
        position: absolute;
        left: 0px;
        top: 0;
    } 
    

    整体效果:(注意z-index的设置):



    最后把开头和结尾的稍微修饰一下:

    .progress-bar li {
        padding-left: 25px;
    }
    .progress-bar li:first-child {
        border-radius: 4px 0 0 4px;
    }
    .progress-bar li:first-child:before {
        display: none;
    }
    

    被选中:

    .progress-bar li.active {
        background-color: #ef72b6;
    }
    .progress-bar li.active:after {
        border-left-color: #ef72b6;
    }
    

    完结。
    最后 来个整体版本:

  • 买家下单
    下单时间
    2019-03-12 22:00:01
  • 买家付款
    付款时间
    2019-03-12 22:01:01
  • 发货
  • 买家确认收货
  • .progress-bar li {
        padding: 0px 20px;
        line-height: 40px;
        background: #50abe4;
        display: inline-block;
        color: #fff;
        position: relative;
        width: 180px;
        text-align: center;
    }
    .progress-bar li:after {
        content: '';
        display: block;
        border-top: 20px solid transparent;
        border-bottom: 20px solid transparent;
        border-left: 20px solid #50abe4;
        position: absolute;
        right: -20px;
        top: 0;
        z-index: 10;
    }
    .progress-bar li:before{  
        content: '';
        display: block;
        border-top: 20px solid transparent;
        border-bottom: 20px solid transparent;
        border-left: 20px solid #fff;
        position: absolute;
        left: 0px;
        top: 0;
    }
    .progress-bar li {
        padding-left: 25px;
    }
    .progress-bar li:first-child {
        border-radius: 4px 0 0 4px;
    }
    .progress-bar li:first-child:before {
        display: none;
    }
    .progress-bar li.active {
        background-color: #ef72b6;
    }
    .progress-bar li.active:after {
        border-left-color: #ef72b6;
    }
    .bar-date {
        position: absolute;
        color: #000;
        font-size: 12px;
        line-height: 20px;
        text-align: center;
    }
    .bar-date span{
        font-size: 12px;
        color: #999;
    }
    


    借鉴地址:https://www.jb51.net/css/529202.html

    你可能感兴趣的:(css实现箭头进度条)