Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make a gradient border? [duplicate]

As the title states, is it possible to make a gradient border in CSS3 and if so how? I know that you can make gradient backgrounds and there are many generators for that, but I am yet to find one that creates the code for a gradient border.

like image 656
Vasseurth Avatar asked Jul 08 '11 03:07

Vasseurth


People also ask

Can I give linear gradient to border?

The first linear gradient is limited to the padding box (i.e., all the content of the element, except the borders).

How do you make a gradient border?

To show gradients for a border with CSS you can use the border-image property. It allows setting gradient values in the same way as the background-image property. Besides the border-image property, you should specify additional properties to actually show border gradient.

Can Borders have gradients CSS?

Gradient borders are not directly supported by using CSS.


2 Answers

You can try this:

div {
  width: 170px;
  height: 48px;
  border-radius: 24px;
  border-style: solid;
  border-width: 2px;
  border-image-source: linear-gradient(to bottom, #fff042, #ff5451);
  border-image-slice: 1;
  background-image: linear-gradient(to bottom, #f9e6e6, #c5e0c3), linear-gradient(to bottom, #fff042, #ff5451);
  background-origin: border-box;
  background-clip: content-box, border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
}
<div>button</div>
like image 128
al-bulat Avatar answered Sep 18 '22 14:09

al-bulat


Nothing to do much just add following code:

 border-image: linear-gradient(to bottom, black 0%, white 100%);
  /* border-image-slice: 1;*/

just add above code to the element and border-image-slice property will set the inner offsets of the element.

like image 33
Suren Neware Avatar answered Sep 17 '22 14:09

Suren Neware