Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get different colors with radius inside a single div?

I am trying to achieve radius in a single. Well let me show what I am trying and what I want:

.bar{
  height: 20px;
  border-radius: 2.5rem;
  background: linear-gradient(to right,  green 0%, green 50%,gray 50%,gray 100%);
}
<div class='bar'></div>

With this code I am getting the sharp right side with green color. I want a rounded right side where the green color ends. something like :
enter image description here

You can see the smooth round green end

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can achieve it with the help of ::after pseudo-element

.bar{
  height: 20px;
  border-radius: 2.5rem;
  background: gray;
  position: relative;
}
.bar::after{
  content: "";
  position: absolute;
  top:0;
  left:0;
  width: 50%;
  height: 20px;
  border-radius: 2.5rem;
  background: green;
}
<div class="bar"></div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading