I would like to create border with linear gradient border, rounded corners and transparent background.
I have:
.btn-gradient-1 {
border-width: 4px;
border-style: solid;
border-image: linear-gradient(to right, darkblue, darkorchid) 1;
}
.btn-gradient-2 {
background: linear-gradient(white, white) padding-box, linear-gradient(to right, darkblue, darkorchid) border-box;
border-radius: 50em;
border: 4px solid transparent;
}
.parent {
display: flex;
flex-wrap: wrap;
gap: 1rem;
background-color: red
}
<div class="parent">
<button class="btn-gradient-1">Button One</button>
<button class="btn-gradient-2">Button Two</button>
</div>
Problem is that linear-gradient
not accept transparent
color value. Is there any hack? The button must have transparent background.
2
Answers
Try this:
I used a combination of a
linear gradient
and aradial gradient
forbackground
.The
background-origin
andbackground-clip
properties are used to specify that thelinear gradient
should only fill thepadding
area of the button, while theradial gradient
should fill theborder
area.I applied my styles to the first
button
.To add transparency, we use the
rgba()
function to define the color stops. The last parameter in thergba()
function can be a value from 0 to 1, and it defines the transparency of the color: 0 indicates full transparency, 1 indicates full color (no transparency).Your transparency will start from
darkblue
(0 0 153) todarkorchid
(153 50 204)