CSS로 원형 진행 막대를 만드는 방법은 무엇입니까?
使用HTML创建基础结构,通过自定义属性--progress设置进度值;2. 利用CSS的conic-gradient根据--progress生成彩色扇形背景;3. 通过伪元素::before配合inset和border-radius裁剪出中心区域,形成环形;4. 可选添加带样式的span标签作为中心文字标签;5. 整体通过flex布局居中内容,实现一个纯CSS的圆形进度条,最终效果为一个75%绿色填充、25%灰色剩余的环形进度条,且可通过JavaScript动态更新进度值并实现动画效果。
Creating a circular progress bar with CSS involves combining HTML structure and CSS styling, often using CSS conic-gradient
, clip-path
, or pseudo-elements with border-radius tricks. One of the most modern and flexible approaches uses conic-gradient
and background
properties. Here’s how to do it step by step.

1. Basic Structure with HTML
Start with a simple container element that will represent the circle:
<div class="circular-progress" style="--progress: 75;"></div>
Here, we're using a custom CSS property --progress
to control the fill level (75% in this case).

2. Styling the Circle with CSS
Use CSS to create the circular shape and apply the gradient based on the progress value.
.circular-progress { width: 120px; height: 120px; border-radius: 50%; background: conic-gradient( #4caf50 var(--progress), #e0e0e0 var(--progress) ); position: relative; }
This creates a pie-chart-like effect where the green color (#4caf50
) fills up to the percentage defined by --progress
, and the rest is gray (#e0e0e0
).

But this fills the entire circle. To make it look like a ring, we need to mask the center.
3. Creating the Hollow Center (Ring Effect)
Use a pseudo-element or a clip-path
to cut out the center and form a ring.
Option A: Using clip-path
(Simpler)
.circular-progress { width: 120px; height: 120px; border-radius: 50%; background: conic-gradient( #4caf50 calc(var(--progress) * 1%), #e0e0e0 calc(var(--progress) * 1%) ); clip-path: inset(15px); }
clip-path: inset(15px)
removes a margin from all sides, creating a ring. But this isn't perfectly centered or scalable.
Option B: Using a Pseudo-element (Recommended)
.circular-progress { width: 120px; height: 120px; border-radius: 50%; background: conic-gradient( #4caf50 calc(var(--progress) * 1%), #e0e0e0 calc(var(--progress) * 1%) ); position: relative; } .circular-progress::before { content: ''; position: absolute; inset: 15px; /* Controls thickness of the ring */ background: #fff; /* This masks the center */ border-radius: 50%; }
This method gives a clean ring. The inset: 15px
creates a smaller circle inside, revealing only the outer ring.
4. Adding a Label (Optional)
You can add a text label in the center using another pseudo-element or a child element.
<div class="circular-progress" style="--progress: 60"> <span class="label">60%</span> </div>
.label { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-family: Arial, sans-serif; font-size: 18px; font-weight: bold; color: #333; }
Make sure the parent has position: relative
.
5. Full Working Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Circular Progress Bar</title> <style> .circular-progress { width: 120px; height: 120px; border-radius: 50%; background: conic-gradient( #4caf50 calc(var(--progress) * 1%), #e0e0e0 calc(var(--progress) * 1%) ); position: relative; display: flex; justify-content: center; align-items: center; } .circular-progress::before { content: ''; position: absolute; inset: 15px; background: #fff; border-radius: 50%; } .label { font-family: Arial, sans-serif; font-size: 18px; font-weight: bold; color: #333; z-index: 1; } </style> </head> <body> <div class="circular-progress" style="--progress: 75"> <span class="label">75%</span> </div> </body> </html>
Important Notes
- The
conic-gradient
method is not supported in older browsers like Internet Explorer. - For dynamic updates, you can change
--progress
via JavaScript:document.querySelector('.circular-progress').style.setProperty('--progress', 90);
- To animate the progress, use CSS transitions on
--progress
— but note: CSS doesn't animate custom properties directly. You’ll need a workaround using@property
(experimental) or JavaScript animation.
Alternative: Stroke-based (SVG) Method
While this question was about pure CSS, many developers use SVG for more control and animation support. But for a pure CSS solution, the conic-gradient + pseudo-element method is clean and effective.
That’s it. You now have a responsive, customizable circular progress bar using only HTML and CSS. Basically just a clever use of gradients and masking.
위 내용은 CSS로 원형 진행 막대를 만드는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undress AI Tool
무료로 이미지를 벗다

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Stock Market GPT
더 현명한 결정을 위한 AI 기반 투자 연구

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

HTML 및 CSS를 사용하여 JavaScript없이 드롭 다운 메뉴를 만듭니다. 2. 호버 의사 클래스를 통해 하위 메뉴 디스플레이를 트리거합니다. 3. 중첩 된 목록을 사용하여 구조를 구축하고 CSS에 숨겨진 및 매달린 디스플레이 효과를 설정하십시오. 4. 시각적 경험을 향상시키기 위해 전환 애니메이션을 추가 할 수 있습니다.

ThePointer-EventsPropertyIncsscontrolswheTheranElementCanBethetArgetOfPointerEvents.1.UsePointer-Events : nonetodisableInterActionSlikeClickSorHoverSwHileKepingTheElementSibleSible.2.AppLyItToOverLayStoClick-throughtounderlyELELENELENELENELEMEN

사용 OBJECT-FITORMAX-WIDTHWITHHEIGHT : AutoTopRevEntImagedIsportion; 개체-피트 컨트롤 하위 링크 컨테이너 및 max width : 100%;

usethebox-shadowpropertytoadddropshadows.definehorizontalandverticaloffsets, 흐림, 스프레드, 색상 및 옵션 alinsetforinnershadows.multipleshadowsarecomma-separated.example : box-shadow : 5px10px8pxrgba (0,0,0,0.3);

thecssfilterpropertyallowseaseasyimagestylingwitheffects likeblur, brightness, andgrayscale.usefilter : 필터-기능 (value) onimagesorbackgroundimages.commonFunctionsIncludeBlur (px), 밝기 (%), Grayscale (%), 채도 (%) 및 hue-merate (degrotate)

CSS 그라디언트 배경을 추가하려면 배경 또는 배경 이미지 속성을 사용하여 Linear-Gradient (), Radial-Gradient ()와 같은 함수와 협력하십시오. 먼저 그라디언트 유형을 선택하고 방향과 색상을 설정하고 컬러 도킹 포인트, 모양, 크기 및 선형 그레이드 (Toright,#ff7e5f,#feb47b)와 같은 기타 매개 변수를 통해 미세하게 제어하여 왼쪽에서 오른쪽으로 선형 그라디언트를 생성하여 Radial-Gradient (원,#ff9a9e,#fecfef)를 생성하여 원형 구배를 만들어냅니다.

Border-Radius : 50%를 사용하여 폭과 높이의 이미지를 원으로 바꾸고, 객체 적합 및 종횡비를 결합하여 모양과 자르기를 보장하고, 경계, 그림자 및 기타 스타일을 추가하여 시각 효과를 향상시킵니다.

간격, 행 갭 또는 열 갭 속성을 사용하여 CSSGRID 레이아웃에서 그리드 항목간에 간격을 만듭니다. GAP는 한두 길이의 값을 수용 할 수있는 행 열격 간격을 설정하기위한 약어 속성입니다. 행 갭 및 열 갭은 행과 열 사이의 간격을 개별적으로 제어하고 PX, REM 및 %와 같은지지 장치를 제어합니다.
