Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create multi-color border with CSS?

How to create multi-color border like image below?

enter image description here

like image 998
Hamed mayahian Avatar asked Aug 09 '16 12:08

Hamed mayahian


People also ask

How do you add multiple colors to a border in CSS?

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.

Can you style 4 different colors to a border in CSS?

You can use the border-image property to create a gradient border with 4 colors.

Can you have 2 borders CSS?

Multiple borders in CSS can be done by box-shadow property. Generally, we can get a single border with border property. Box-shadow property is not for multiple borders, but still, we are creating multiple borders with box-shadow property.


1 Answers

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>
like image 157
Theodore K. Avatar answered Oct 31 '22 11:10

Theodore K.