cssborderlinear-gradientsrepeating-linear-gradient

How create solid rainbow border with CSS?


How to create the following rainbow effect using CSS?

i.e. top rounded border with solid rainbow color stops (without inserting html).

enter image description here

Colors are: #c4e17f. #f7fdca, #fad071, #f0766b, #db9dbe, #c49cdf, #6599e2, #61c2e4.

What I have tried so far:

.container {
  background: #596678;
  width: 100%;
  height: 300px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.top-round-rainbow {
  width: 50%;
  height: 50%;
  background: white;
  border-radius: 4px;
  
  background-image: repeating-linear-gradient(to right, #c4e17f 50px, #f7fdca 50px, #fad071 50px, #f0766b, #db9dbe, #c49cdf, #6599e2, #61c2e4);
}
<div class="container">
  <div class="top-round-rainbow">
  </div>
</div>


Solution

  • You're not that far off. Just need to set the color stops with equal values so they act as solid colors, and the background size to have it only on top.

    .container {
      background: #596678;
      width: 100%;
      height: 300px;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    
    .top-round-rainbow {
      width: 400px;
      height: 50%;
      background: white;
      border-radius: 4px;
      
      background-image: repeating-linear-gradient(to right,
      #c4e17f 0px, #c4e17f 50px,
      #f7fdca 50px, #f7fdca 100px,
      #fad071 100px, #fad071 150px,
      #f0766b 150px, #f0766b 200px,
      #db9dbe 200px, #db9dbe 250px,
      #c49cdf 250px, #c49cdf 300px,
      #6599e2 300px, #6599e2 350px,
      #61c2e4 350px, #61c2e4 400px);
      background-size: 100% 10px;
      background-repeat:no-repeat;
    }
    <div class="container">
      <div class="top-round-rainbow">
      </div>
    </div>