赞
踩
我们平时写进度条一般是一个父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>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。