What technique is used to fill these circular progress indicators?

I stumbled upon some circular progress bars and I'm a bit confused about how they are filled. Check out this codepen link: https://codepen.io/anon/pen/aeEEmx

From what I understand, when using gradients with specified positions (degrees in this case), it should start where you specify the value. For example, in the CSS for the progress-20 class, there's a linear gradient with 18 deg followed by another one with 90deg, but I can't wrap my head around how these values work together - 18deg and 90deg or -18deg and 90deg as seen in the one with 30%.

Here is the code snippet:

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  background-color: #fff;
  font-family: "Lato", "Arial", "san-serif";
  color: #555;
  font-size: 20px;
  font-weight: 300px;
  text-rendering: optimizeLegibility;
}

.radialProgressBar {
  border-radius: 50%;
  -webkit-transform: translate(50%, 50%);
  transform: translate(50%, 50%);
  width: 100px;
  height: 100px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  background: #ddd;
  margin: 20px;
}

.radialProgressBar .overlay {
  border-radius: 50%;
  width: 80px;
  height: 80px;
  margin: auto;
  background: #fff;
  text-align: center;
  padding-top: 30%;
}

.progress-20 {
  background-image: linear-gradient(18deg, #ddd 50%, transparent 50%), linear-gradient(90deg, #028cd5 50%, #ddd 50%);
}

.progress-30 {
  background-image: linear-gradient(-18deg, #ddd 50%, transparent 50%), linear-gradient(90deg, #028cd5 50%, #ddd 50%);
}

.progress-40 {
  background-image: linear-gradient(-54deg, #ddd 50%, transparent 50%), linear-gradient(90deg, #028cd5 50%, #ddd 50%);
}

.progress-70 {
  background-image: linear-gradient(90deg, #028cd5 50%, transparent 50%), linear-gradient(18deg, #028cd5 50%, #ddd 50%);
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <div class="radialProgressBar progress-20">
    <div class="overlay">20</div>
  </div>
  <div class="radialProgressBar progress-30">
    <div class="overlay">30</div>
  </div>
  <div class="radialProgressBar progress-40">
    <div class="overlay">40</div>
  </div>
  <div class="radialProgressBar progress-70">
    <div class="overlay">70</div>
  </div>
</body>

</html>

Answer №1

This design utilizes multiple overlapping gradients to create a unique effect. By using different colors for each gradient, the technique becomes more apparent. The 90-degree gradient divides the chart in half, while another gradient at a different angle (18 degrees in this example) overlays the remaining area of the blue color, showcasing only the necessary blue sections.

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  background-color: #fff;
  font-family: "Lato", Arial, sans-serif;
  color: #555;
  font-size: 20px;
  font-weight: 300;
  text-rendering: optimizeLegibility;
}

.radialProgressBar {
  border-radius: 50%;
  transform: translate(50%, 50%);
  width: 100px;
  height: 100px;
  display: flex;
  background: #ddd;
  margin: 20px;
}

.radialProgressBar .overlay {
  border-radius: 50%;
  width: 80px;
  height: 80px;
  margin: auto;
  text-align: center;
  padding-top: 30%;
}

.oneGradient {
  background-image: linear-gradient(90deg, #028cd5 50%, #ddd 50%);
}

.differentColor {
  background-image: linear-gradient(18deg, #aaa 50%, transparent 50%), linear-gradient(90deg, #028cd5 50%, #ddd 50%);
}

.sameColor {
  background-image: linear-gradient(18deg, #ddd 50%, transparent 50%), linear-gradient(90deg, #028cd5 50%, #ddd 50%);
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <div class="radialProgressBar oneGradient">
    <div class="overlay"></div>
  </div>
  <div class="radialProgressBar differentColor">
    <div class="overlay"></div>
  </div>
  <div class="radialProgressBar sameColor">
    <div class="overlay"></div>
  </div>
</body>

</html>

Answer №2

This particular design utilizes an SVG element. It may seem simple, but you can easily adjust the animation by modifying the stroke-dasharray property to control the running effect. In this code snippet, "73" represents the current percentage while "100" indicates the total.

.percentage-container {
    width: 280px;
    height: 280px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 100%;
    position: relative;
    overflow: hidden;
}

.progress {
    background-color: rgba(209,218,225,.3);
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    stroke: #FF4C1D;
    stroke-width: 10px;
    stroke-dasharray: 73, 100;
    transition: stroke-dasharray 280ms cubic-bezier(0.4,0,0.2,1);
    -webkit-transition: stroke-dasharray 280ms cubic-bezier(0.4,0,0.2,1);
}

.percentage-inner-container {
    width: 90%;
    height: 90%;
    border-radius: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #FFF;
    z-index: 1;
}

.percentage-amount {
    font-family: 'Arial', sans-serif;
    font-size: 70px;
    color: #34495E;
}

.percentage-amount::after {
    content: '%';
    font-size: 26px;
    position: relative;
    bottom: 30px;
}
<div class="percentage-container">
     <svg class="progress" viewBox="0 0 36 36"><path d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831"></path></svg>
     <div class="percentage-inner-container">
          <span class="percentage-amount">73</span>
     </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Display various divs simultaneously based on the quantity of items in the dropdown menu

In my project, there is a dynamic select list that retrieves items from the database. Users have the ability to add or delete items from this list. Below is some code related to this functionality: <div class="form-group col-md-3"> <la ...

issue with border in hover effect on navigation menu

I'm looking to replicate a menu design similar to the one shown in this image. My main issue lies with the hover effect, specifically changing the vertical images on both sides. I've made some progress so far and you can view it here: http://jsf ...

Various degree of stacking priority ordering

I was faced with a coding dilemma that I couldn't quite figure out. The title may not give much away, but the issue lies within this code snippet: https://jsfiddle.net/bnh3487n/ div { width: 100%; } #wrapper { width: 500px; height: 500px; ...

Click Event for Basic CSS Dropdown Menu

My goal is to develop a straightforward feature where a dropdown menu appears below a specific text field once it is clicked. $(".val").children("div").on("click", function() { alert("CLICK"); }); .container { display: inline-block; } .val { d ...

Is Javascript the best choice for managing multiple instances of similar HTML code?

I am currently facing the challenge of dealing with a lengthy HTML page consisting of around 300 lines of code. The majority of the code involves repetitive forms, each identical except for the ID (which varies by number). Is it considered appropriate or ...

Using local storage with github sites can lead to some unexpected and peculiar behavior

Currently, I am working on a simple clicker game using HTML and JavaScript. To store the variables money and taxCollecters, I have implemented local storage. However, I am encountering strange issues when trying to use the save and load buttons on the Gi ...

Can I apply CSS styling to an entire row within a column?

When using the Bootstrap 4 Grid system, my structure looks like this: https://i.sstatic.net/MB2C7.png Inside each row, I have a content column and two empty columns. At times, I need to style the entire row with CSS. <div class="container"> <d ...

When adjusting the max-height and overflow-y in a Boostrap 4 Navbar with a search input/icon placement set to absolute position, the functionality seems to break

While attempting to create a search input with an embedded search icon that works within the Bootstrap 4 navbar when the mobile menu is displayed, I encountered some challenges. The process was much simpler in my previous version using Bootstrap 3... http ...

What is the best method for incorporating an Angular Component within a CSS grid layout?

I recently started learning Angular and am currently working on a project that requires the use of a CSS grid layout. However, I'm facing an issue with inserting a component inside a grid area specified by grid-area. My attempt to achieve this in app ...

What is the best way to showcase images in a horizontal layout with the help of PHP and

Does anyone know how to retrieve images from a MySQL database and display them in rows of three horizontally, while also having a relevant image show on top? I'm struggling with this task. Below is the code snippet for the main div: <div class="co ...

The CSS3 feature is not compatible with the Android browser, causing issues with loading responsive CSS

Currently, I am conducting testing on my website across various mobile devices. So far, the site functions perfectly on iOS devices but encounters issues when viewed on Android devices - it appears zoomed in and fails to be responsive. Within the <head ...

Is it possible to find a match by searching through multiple arrays for a corresponding variable name?

Hi there, I'm currently working on a function that triggers an alert if the name of an array of images matches the data attribute of the selected element. This is just a test phase before proceeding with my main project, but I've hit a roadblock. ...

Compatibility Problem with Form Inputs in Internet Explorer 7 when Using a jQuery Datepicker

I've encountered a frustrating issue with my Reservations area (jquery ui datepicker) on the site I'm currently working on. When viewed in IE7, the datepicker is broken and displayed on separate lines. If you'd like to check it out yourself ...

Tips for extracting the text from the most recent chat bubble while automating a chatbot with Selenium

While attempting to automate a chatbot using Selenium, I am facing an issue where the code is retrieving the text from the first chat bubble instead of the latest one. How can I modify my code to extract the text from the most recent chat bubble, especiall ...

Using the <script> attribute within the <head> tag without the async or defer attributes

https://i.stack.imgur.com/cRFaR.pngCurious about Reddit's use of the async or defer attribute in the script tag. Are there situations where blocking the parser is necessary? ...

Control other inputs according to the chosen option

Here is the HTML code snippet: <fieldset> <label for="tipoPre">Select prize type:</label> <select id="tipoPre"><option value="Consumer Refund">Consumer Refund</option> <option value="Accumulated Prize Ref ...

What is the purpose of using translateY(-50%) to vertically center an element that is positioned at top: 50%?

I've noticed that this code successfully aligns a div vertically within its parent element: .element { position: relative; top: 50%; transform: translateY(-50%); } My curiosity lies in the reasoning behind this. Initially, I thought that the p ...

Adjusting linear gradient when the color picker is modified

My website has a default linear gradient over an image, which is controlled by the following HTML and TypeScript code: <header [style.background-image]="cv2HeaderStyle('0, 0, 0, 0.1', '0, 0, 0, 0.8')"></header> cv ...

Building Custom Navigation for a Multilingual Website in Concrete5

I am trying to build a multilingual website using Concrete5 (v 5.7). My custom theme has the following page layout: Home |-en |--Frontpage |--Contatcs |-<language2> |--<Frontpage> |--<Contacts> The current navigation implementation is ...

Organizing CSS DIV code by sections for desktops and mobile devices

My CSS file contains properties that are common for both PC and cellphone browsing, but some vary between the two platforms. I utilize @media screen and (max-width: X px) to handle this, with one set of rules for narrow screens and another for wider screen ...