How to create multi-color border with CSS?

Solution 1:

You can do it without pseudo-elements, just with border-image: linear-gradient

.fancy-border {
  width: 150px;
  height: 150px;
  text-align:center;
  border-top: 5px solid;
  border-image:   linear-gradient(to right, grey 25%, yellow 25%, yellow 50%,red 50%, red 75%, teal 75%) 5;
}
<div class="fancy-border">
  my content
</div>

Solution 2:

You can do it with :after or :before psuedo element and css linear-gradient as shown below:

body {
  background: #ccc;
}

.box {
  text-align: center;
  position: relative;
  line-height: 100px;
  background: #fff;
  height: 100px;
  width: 300px;
}

.box:after {
  background: linear-gradient(to right, #bcbcbc 25%,#ffcd02 25%, #ffcd02 50%, #e84f47 50%, #e84f47 75%, #65c1ac 75%);
  position: absolute;
  content: '';
  height: 4px;
  right: 0;
  left: 0;
  top: 0;
}
<div class="box">Div</div>