Flying Gambit
Flying Gambit

Reputation: 1276

How to create a multi-colored border?

How to create a border that is uneven and multicolored similar to the below image ?

enter image description here

Upvotes: 0

Views: 196

Answers (2)

Takit Isy
Takit Isy

Reputation: 10081

You can use pseudo-elements ::before and ::after to achieve that:

.box {
  position: relative;
  background: #66d;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 6px solid #ddd;
}

.box::before, .box::after {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: -6px; /* width of the border */
  border-radius: 50%;
  border: 6px solid transparent;
  content: '';
}

.box::before {
  border-top-color: #bbb;
  transform: rotate(45deg);   /* 45deg to start right on top */
}

.box::after {
  border-right-color: #bbb;   /* You can color the borders you want… */
  /* transform: rotate(0deg); /* … and adjust the rotation if needed */
}
<div class="box"></div>

Note that you could make more borders visible if you need.

Hope it helps.

Upvotes: 2

Temani Afif
Temani Afif

Reputation: 272648

You can use gradient to create this:

.box {
  width:100px;
  height:100px;
  border-radius:50%;
  background:
   radial-gradient(circle at center, blue 60%,transparent 60.1%),
   linear-gradient(to right,#fff 50%,transparent 0),
   linear-gradient(50deg,#fff 50%,transparent 0),
   red;
}
<div class="box">

</div>

Upvotes: 1

Related Questions