用css写进度条

19 篇文章 0 订阅
用css写进度条

我们平时写进度条一般是一个父div包裹一个子div,用js控制子div的宽度 实现进度条,我们现在可以用css简单实现进度条了。
代码如下:
在vue项目里咱们只需要控制数字就行了,非常简单方便
在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .bar{
            height: 20px;
            width: 300px;
            background-color: #f5f5f5;
        }
        .bar::before{
            display: block;
            counter-reset: progress var(--precent); 
            content: counter(progress) '%';
            width: calc(1% * var(--precent));
            color: #fff;
            background-color: #2486ff;
            text-align: center;
            white-space: nowrap;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <div class="bar" style="--precent:93;"></div>
</body>
</html>


在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            counter-reset: sec;
            margin-left: 200px;
        }

        h1{
            counter-reset: sub;
        }

        h1::before{
            counter-increment: sec;
            content: counter(sec) '. ';
        }
        
        h2{
            height: 30px;
            width: 300px;
            background-color: #f4f4f4;
            font-size: 20px;
        }
        h2::before{
            display: inline-block;
            counter-reset:  progress var(--precent);
            content: counter(progress) "%" ;
            background-color: #2486ff;
            width:calc(1% * var(--precent));
            white-space: nowrap;
            text-align: center;
            font-size: 20px;
            color: #fff;
        }

    </style>
</head>
<body>
    <div class="box">
        <h1 >早上</h1>
        <h2 style="--precent:30;">起床</h2>
        <h2 style="--precent:40;">刷牙</h2>
        <h2 style="--precent:60;">洗脸</h2>
        
        <h1 style="--precent:20;">中午</h1>
        <h2 style="--precent:30;">吃饭</h2>
        <h2 style="--precent:66;">午睡</h2>
        <h2 style="--precent:18;">玩手机</h2>
    
    
        <h1 >晚上</h1>
        <h2 style="--precent:16;">关电脑</h2>    
        <h2 style="--precent:20;">写日报</h2>    
        <h2 style="--precent:30;">下班</h2>    
    </div>
    
</body>
</html>



在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            counter-reset: sec;
            margin-left: 200px;
        }
        h1{
            counter-reset: sub;
        }
        h1::before{
            counter-increment: sec;
            content: counter(sec) '. ';
        }
        h2::before{
            counter-increment: sub;
            content:counter(sec) "." counter(sub) " " ;
        }
    </style>
</head>
<body>
    <div class="box">
        <h1>早上</h1>
        <h2>起床</h2>
        <h2>刷牙</h2>
        <h2>洗脸</h2>
        
        <h1>中午</h1>
        <h2>吃饭</h2>
        <h2>午睡</h2>
        <h2>玩手机</h2>
    
        <h1>晚上</h1>
        <h2>关电脑</h2>    
        <h2>写日报</h2>    
        <h2>下班</h2>    
    </div>
    
</body>
</html>
  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端酱紫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值