How to implement a circular progress bar in css: first draw a square; then draw two rectangles of equal size in the square; finally use the "transform:rotate" attribute of css3 to superimpose the ring according to the actual situation Just convert the percentage into actual rotation angle.
The effect processing of the full circle will be simpler, and the implementation of the incomplete ring will be more detailed. The following is the implementation logic and process. Progress bar composition: Ring: Two colors of progress bar. When the balance is less than 50%, the color of the progress bar changes from green to yellow. The progress bar structure consists of two superimposed rings; the upper superimposed ring shows the remaining amount, dark color; the lower superimposed ring shows 100% of the total amount, light color. Style implementation: 1: Draw a square, as shown in the shaded part in the picture:
2: Draw two equally divided squares in the square rectangle, (note that each rectangle must be set: overflow:hidden) as shown in the shaded part of the figure:
3: The progress bar is composed of two superimposed rings, Therefore, in the square in the first step, four rectangles of equal size need to be drawn to show different parts of the ring. 4: Draw a square in each rectangle that is the same size as the parent square to display the ring. The ring in the left half rectangle only sets the upper and left borders; the ring in the right half rectangle only sets the top border and left border. The upper border and the right border, as shown by the shadow in the picture:
#5: To realize the dynamic percentage progress of the progress bar, use CSS3's transform:rotate to superimpose the ring according to the actual situation The percentage is converted into actual rotation angle.
When the remaining amount is greater than 50%, the superimposed annular rotation angle on the left does not need to be changed, and only the superimposed annular rotation angle on the right is calculated. When the remaining amount is less than 50%, when the ring rotation is superimposed on the left side, the left half ring will be displayed as a complete half ring. At this time, a ring is needed to cover the left part of the ring that exceeds the progress range. The left ring of The circular rotation angle conversion needs to be fine-tuned according to different needs.
If you have any good suggestions, please feel free to share them.
The above is the detailed content of How to implement a circular progress bar in css. For more information, please follow other related articles on the PHP Chinese website!
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn