How apply this border gradient?
I'm trying to solve it using https://css-tricks.com/gradient-borders-in-css/ and https://theodorusclarence.com/blog/gradient-border-is-hard but I'm not getting to do it. Can anyone help me please?
the button background is a background using a linear-gradient that to have opacity
Chris Coyier
CSS-Tricks
Gradient Borders In CSS | CSS-Tricks
Let's say you need a gradient border around an element. My mind goes like this:
theodorusclarence.com
Gradient Border is Unexpectedly Hard | theodorusclarence.com
A simple gradient border is not as simple as it seems.
21 Replies
can you show us what you've done so far? A codepen link?
I'll to make one (sorry if I don't to speak so correcty, I don't speak english so well)
I'm not sure if it's a good template
https://codepen.io/pen?template=WNVXQq
Not sure if this is what you are looking for, but this is how I make gradient borders on elements with fully or partially transparent backgrounds:
You define the gradient as a background on a pseudo element.
Yes, it works! Can you explain how I can understand it? I've never used a mask for this purpose before
oh, I'm sorry, was a mistaken
Without mask the pseudo element with the gradient will cover the entire element. So we use mask to cut trough the pseudo element, but only the padding-box. Whatβs outside the padding-box (which is the border area) is left intact.
oh, it's cool
Thank you so much for helping me solve this problem, @nilaallj ! I just don't know how to remove these 'lines' π
. It should be a gradient going to the top
i think which it's a problem in my code I'll try to see it in my browser. I'm applying a border in my button
Can you provide a codepen link? (:
I'm using tailwind and react, I don't know how to configure it in the Codepen : (
Ah, I see. I think this might be because
background-origin
is not set to border-box
. In my example I used the background
shorthand which should set border-box
on both background-origin
and background-clip
.
So by using the background longhands it should look like this:
it work! I just don't know why the border of the component is over the border with the gradient
Screenshot?
Does the border on the main element have
transparent
set as color?
Not sure whatβs going on here to be honest. Maybe check the calculated values in the inspector to make sure they match my example?
It could have something to do with the mask also.yes, the border is calculated as 2px, the border also is applied as transparent, I don't understand the reason for it don't work
Itβs strange. I have pretty much exactly the same code in front of me right now and it works. Have a look: https://codepen.io/nilaallj/pen/dyBLqbV
I don't understand, I'll see if has something affecting my result
@nilaallj thanks you so much! : D it worked for me, I am very grateful
Glad to hear that. Youβre welcome!