Search code examples
cssbordercss-shapes

How to create multi-color border with CSS?


How to create multi-color border like image below?

enter image description here


Solution

  • 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>