当前位置:网站首页>How to create a progress bar that changes color according to progress
How to create a progress bar that changes color according to progress
2022-07-01 05:21:00 【Phil Arist】
Progress bar is a common function on Web pages , however , Do you know how to create a progress bar that automatically adjusts the color according to the progress ?
The effect is as follows :

The requirements are :
Progress in 80% and 100% Between , Please set the background color to green .
Progress in 60% To 80% Between , Set the background color to blue .
Progress in 40% To 60% Between , Set the background color to purple .
Progress in 20% and 40% Between , Set the background color to yellow .
Progress in 0% To 20% Between , Set the background color to red .
According to this requirement , Let's discuss this topic today .
01、 Create a progress bar
First , We need to create a progress bar . By using <progress> Tab create progress bar .
But in the following example , We need to use CSS Variable , And this label is inappropriate . So we use conventional div Labels and some CSS Style to create a progress bar .
The progress bar consists of two parts :
Containers
progress
To create a container , We just need to create one div Elements :
<div class="bar" style="--percent: 50;"></div>We use CSS Variable percentage to indicate progress .
Then we can use pseudo class elements to create progress parts .
.bar {
height: 20px;
background-color: #f5f5f5;
}
.bar::before {
content: '';
display: flex;
justify-content: end;
width: calc(var(--percent) * 1%);
height: 100%;
background: #2486ff; white-space: nowrap;}

02、 Color change
How can we achieve the effect of automatic color change ?
A trick : Set multiple background layers , Each background layer has a different color . Then we can adjust the background color indirectly by adjusting the layer .
When red and blue layers are stacked together , Red background . If we hide the red layer again , The background will turn blue .
If we were to 5 Hierarchically linked , Make the upper layer a little shorter , We will get the following results :
codepen Demonstration effect :https://codepen.io/bytefishmedium/pen/rNdaMYg
03、 Combine
Last , We need to merge the previous code , You can get a progress bar that can automatically adjust the color change .
Here it is , The effect of the color change progress bar I want to share with you is over , Thanks for reading .
边栏推荐
- Set集合详细讲解
- Mathematical knowledge: finding the number of divisors
- Flutter can refresh data every time the interface comes in
- 每日一题-LeetCode1175-质数排列-数学
- QDataStream的简单读写验证
- [summer daily question] Luogu p5886 Hello, 2020!
- Numeric amount plus comma; JS two methods of adding three digits and a comma to numbers; JS data formatting
- Global and Chinese market of high-end home theater 2022-2028: Research Report on technology, participants, trends, market size and share
- Worried about infringement? Must share copyrightless materials on the website. Don't worry about the lack of materials for video clips
- Rainbow combines neuvector to practice container safety management
猜你喜欢

Single page application

Intelligent operation and maintenance: visual management system based on BIM Technology

Distributed architecture system splitting principles, requirements and microservice splitting steps

Lock free concurrency of JUC (leguan lock)
![[RootersCTF2019]babyWeb](/img/b4/aa8f8e107a9dacbace72d4717b1834.png)
[RootersCTF2019]babyWeb

0xc000007b应用程序无法正常启动解决方案(亲测有效)

Leetcode316- remove duplicate letters - stack - greedy - string

Use and principle of wait notify

轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
![[summer daily question] Luogu p5886 Hello, 2020!](/img/ac/4be05f80aab7fb766674e6e2d16fbc.png)
[summer daily question] Luogu p5886 Hello, 2020!
随机推荐
Numeric amount plus comma; JS two methods of adding three digits and a comma to numbers; JS data formatting
Tar command
How to start learning editing? Detailed analysis of zero basis
提高企业产品交付效率系列(1)—— 企业应用一键安装和升级
Spanner 论文小结
AcWing 887. Finding combinatorial number III (Lucas theorem)
Some common commands of podman
FileInputStream
How to meet the requirements of source code confidentiality and source code security management
Distributed - summary list
实战:redux的基本使用
What can the points mall Games bring to businesses? How to build a points mall?
[daily question in summer] Luogu p2026 find the analytic formula of primary function
Memtable for leveldb source code analysis
Global and Chinese market for instant messaging security and compliance solutions 2022-2028: Research Report on technology, participants, trends, market size and share
Tcp/ip explanation (version 2) notes / 3 link layer / 3.2 Ethernet and IEEE 802 lan/man standards
Worried about infringement? Must share copyrightless materials on the website. Don't worry about the lack of materials for video clips
Intelligent operation and maintenance: visual management system based on BIM Technology
Global and Chinese markets of superconductor 2022-2028: Research Report on technology, participants, trends, market size and share
Causes of short circuit of conductive slip ring and Countermeasures