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>