<!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;
margin: 5px 0 10px;
}
.bar::before {
counter-reset: progress var(--percent);
content: counter(progress) '%\2002';
display: block;
width: calc(300px * var(--percent) / 100);
font-size: 12px;
color: #fff;
background-color: #2486ff;
text-align: right;
white-space: nowrap;
overflow: hidden;
}
</style>
</head>
<body>
<label>图片1:</label>
<div class="bar" style="--percent: 60;"></div>
<label>图片2:</label>
<div class="bar" style="--percent: 40;"></div>
<label>图片3:</label>
<div class="bar" style="--percent: 20;"></div>
</body>
</html>
![](https://img.haomeiwen.com/i13647696/b741086c39fcc5ac.png)
转载自https://www.zhangxinxu.com/wordpress/2020/07/css-var-improve-components/
网友评论