How to create the following rainbow effect using CSS?
i.e. top rounded border with solid rainbow color stops (without inserting html).
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>
To achieve a multi-color border like shown above, we will use the position property and the ::after selector with a color gradient. First, we will make a header area using a HTML <div> class and then we will style it with CSS to have a multi-color border dividing it and the content below.
SVG elements have the stroke-dasharray property, which can be used to make custom borders like that (in an svg). you can then use it as a background image in your html, and it will scale to fill whatever container you put it in.
You can use: border-style: solid; border-width: thin; border-color: #FFFFFF; You can change these as you see fit, though.
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>
You could use after
pseudo-element with linear-gradient
to create border.
.container {
background: #596678;
width: 100%;
height: 300px;
display: flex;
justify-content: center;
align-items: center;
}
.top-round-rainbow {
width: 50%;
height: 50px;
background: white;
border-radius: 4px;
position: relative;
overflow: hidden;
}
.top-round-rainbow:after {
content: "";
position: absolute;
height: 10px;
top: 0;
width: 100%;
left: 0;
background: linear-gradient(to right, rgba(196,225,127,1) 0%, rgba(196,225,127,1) 12%, rgba(247,253,202,1) 12%, rgba(247,253,202,1) 25%, rgba(250,208,113,1) 25%, rgba(250,208,113,1) 39%, rgba(240,118,107,1) 39%, rgba(240,118,107,1) 52%, rgba(219,157,190,1) 52%, rgba(219,157,190,1) 65%, rgba(196,156,223,1) 65%, rgba(196,156,223,1) 78%, rgba(101,153,226,1) 78%, rgba(101,153,226,1) 89%, rgba(97,194,228,1) 89%, rgba(97,194,228,1) 100%);
}
<div class="container">
<div class="top-round-rainbow"></div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With