I have multiple segments in a progress bar, in this example representing two states – achieved and planned values. The planned segment should have a border and nearing the end of the progress bar it should get the same border-radius as the background.
My problem is the following. Either the the radius is also visible within the progress bar, or I don’t use a border-radius for the right corner and use overflow: hidden; to "cut off" the unwanted overflowing part of the segment but then I lose the border on the radius.
Difficult to explain, images are probably better.
This is basically how I want it to look. Is it possible with a reasonably simple solution?
.progress-bar {
position: relative;
height: 40px;
width: 400px;
background: lightgray;
border-radius: 24px;
.segment {
position: absolute;
height: 40px;
box-sizing: border-box;
&:first-of-type {
border-radius: 24px 0 0 24px;
width: 70%;
background: blue;
}
&:last-of-type {
left: 70%;
width: 28%;
background: lightblue;
border: 1px solid blue;
}
}
}
<div class="progress-bar">
<div class="segment"></div>
<div class="segment"></div>
</div>
2
Answers
This is almost what you want:
Setting
border-right: none
doesn’t quite get the last part.Hope this helps!
To create a really simple CSS progress-bar, use a single DIV element with a
linear-gradient
background-image.Pass the percentage value using CSS Custom Properties (Variables) like i.e:
--percent:80;
or just--p:80;
If you need the value visible inside the progress-bar, use a
::before
or::after
pseudo-element:If you need multiple segments, use multiple
--p*
properties