Syntax Video
Gradient borders will be the death of me
Transcript
I'm challenging myself to a lightning round CSS battle where I'm going to see how fast I can get these buttons done. Now, these buttons come from Thiago Alexandrino. The starting code that I have is just five buttons. I'm going to be trying to not only get this done as fast as possible, but make these things actually buttons that I would want to use in my real code. And I'm going to be doing all of this with just CSS, obviously. Now, I've got my stopwatch here. I'm going to hit go on this thing and see how fast I can get this done.
I'll link this up in the description if you want to see how fast you can get these buttons done. We're going to be working on the Honor system here, but use that image. Uh, get these buttons done. Do a custom hover seat on these bad boys and let me know how fast you were able to do it. Even better if you record yourself, share that video, and we'll check it out. Let's get going on this thing. Uh, I have all the stuff here. I do have a div wrapping all of these buttons and so I can just target that div just itself. We're going to do a display flex. We're going to do flex direction column, not a flood color. Uh what in the world? We're going to have a gap of something just like 40 pixels here. And we are going to right now have a max width of this entire thing as like a 600 pixels. Now that's not going to determine the max width of these buttons by any means. So let's go ahead and get our initial button kind of style down.
I'm actually going to start with this kind of gray one right here, or maybe even just the blue one. We're going to have a default button styling. Now, let's zoom in on these to get a good eye of what's going on. Of course, there's plenty of pixels in this, so we're getting a lot of pixels. I'm going to actually pick the color. And the blue one will be the default. So, we'll just have this button color. We'll say this is going to be the main color. And it is going to just be at this point this blue. Now we'll say color is equal to vary color. I'm using CSS variables for this obviously because that way we can just override the variables. But not only that, they'll be able to do some cool stuff. Like for instance, we have this border. We have an inset border. So let's take a look at what we have. We have a light gradient that's going from something to something here. We do have a white on the inset here. And we do have a border that also has what appears to be a gradient. And the border
gradient is a tough thing to do. There's a number of different strategies you can do with a border gradient. Let's go ahead and first and foremost get this background going. So we're going to do a background. We're going to do a linear gradient. We're going to go from or we'll say to bottom [music] and comma. We're going to start from right now vary color. That will change.
And then we're going to go to varyen color. And we're going to use relative color syntax on this thing. I'm going to eyeball this for the most part. The easy way to do this would be do a color picker and just pick this hex value. But that's not how I would do it in real life. So I don't want to do it that way. We're going to say RGB from and we're going to say from the color RGB, we're going to get RGB and then forward slash and we'll say something like 0.2. So from that to that. And actually, I'm just going to straight up duplicate this line and say we're going to go from 0 to 0.5 here. Okay, that honestly, we're saying two bottom from top to bottom.
That actually doesn't look terrible right off the jump, even just zooming in here. So, I'm going to keep that for right now. We're also going to say this has a border of var. Actually, instead of var, I'm going to grab this one right here. We're going to worry about the gradient border after this. We're going to say solid 1 pix. There we go. And the border radius on these things is pretty severe. If you do border radius 50% on this, it makes it look like this. So, you have to use a pixel value for something. And it's hard to give this a pixel value just straight up. Even though I just did it uh 25 pixels and it just looks great here, it's hard to do this and, you know, not know what the size of these buttons is going to be.
But, uh, we'll just keep it at this for right now. If I zoom in on mine, there's some funniness going on with the border and the background gradient. If we do overflow hidden, I actually don't know if that will fix. Doesn't fix. Overflow hidden does not fix. That's interesting is because we currently have a border that has transparency in it. It's overlapping with the linear gradient. I actually don't know about that. That's interesting. Also, this is what they look like right now. So, let's actually give these a font size of something considerably larger for right now. 24 pixels. That at least looks a little bit better here. That way, we're not zoomed in super high. And we have some space here. I'm not going to worry too much about the font. We have some space. The spacing on these is always interesting because what you end up getting, you want buttons that are all the same width. Uh I'll worry about the width part later, but let's do just a padding of something like one rim and then something like 10 pixels. And this is going to give them considerably more
space. Let's do something like 0.75 RAM. Me just uh typing in values till it looks nice. Now, honestly, you could just measure all this and do it all in pixels. And that's probably fine, too. The border definitely needs to be more than one pixel, but probably not that much more. Like two pixels, pretty good here. Um, in terms of what this actually looks like. And now I'm going to actually do the inset box shadow because these have an inset box shadow. You can see already that our our 25 border radius that we had doesn't work. Um, let's bump it up to 35. So, we'll say box shadow inset and we're going to say RGB 255 255 255 uh forward/0.3.
Save this. Actually, this is going to do nothing. I typically put the word inset at the end too, just for consistency sake. And the distance on this thing is going to be 0 0. And let's do like a two pixel blur and a two pixel distance on it. In fact, let's make this right now. Sometimes I do this. I want to see what it looks like. We'll have it be very non-transparent. So the two pixel blur might actually be a little bit much. The one pixel blur looks pretty good. The two pixel like this looks pretty decent.
And then if you bounce out, okay, that might be too much. Again, bump it back down. We're getting pretty close there. But I do have to feel like if we look at these, it is [music] the two pixel blur I think was better representative of their style. So already getting pretty close. Okay, so the way we have these is that there's several buttons. We can add some classes to these. So class and the first one will just be I like to call yellow stuff warning. And then we'll say error for the red. We'll say success for the green. and then ghost for the gray. Why did I just pick these names?
Well, I don't know. I I could have just done edit, remove, except declined. [music] I could have just done that, but instead I did warning, error, success, and ghost because that's what I like to work in. So, uh, warning and then [music] error success ghost. Now, the reason the whole reason we did this with CSS variables in this way is because you can just reassign this color variable here.
We can use the color picker. We can pick this color. We can paste it in here. And we'll be able to see that this now all of a sudden gets us way closer really quickly. In terms of time here, what am I at? I'm at 9 minutes. Okay. Um I was hoping to have this done faster than 9 minutes. Uh but you know me, I'm always way too optimistic. I see this and I could say I could do this in a 10-minute CSS battle, no problem. and then the time comes by and next thing you know you're this far. But ooh it's looking really good already. [music] Now with these buttons I do like to have a padding on the side. But like if we were to say the width of these is something like 200 pixels, right? It gets them all a little bit more similar. Now the big problem ends up being when you do that you end up having long buttons. You got to worry about that. Yeah, it it's something that you do have to be cautious about because the buttons in the example are all the same width no matter what. You could have that be a
max width. Um that would be no max width wouldn't work either cuz then they minimum width would would say that wouldn't work either cuz like if we did min width, they're now going to go way far. I think just straight up width on these is fine for right now. And I do honestly think it's probably way more accurate when I define that width than I was expecting. So, you know what? I I feel like I'm kind of doing a decent job here getting these buttons going pretty quickly. The big thing that we don't have right now is the gradient border. I hate gradient borders, which mine still looks funky. The gradient border is not very chill right now. Uh I do have the inset shadow is looking pretty chill.
And everything else kind of looks right. Honestly, I think the intensity of the gradient for the button itself could maybe be dialed down, but they look pretty glassy and and kind of cool. Okay, let's keep moving. They do have a box shadow on. I don't know if you can see this. We'll say zero for X, but for the Y, it was like something pretty decent, like 20 pixels. The blur is massive. Uh, we'll say 20 pixels for that and zero for the spread. We'll say RGB. We'll give this black because 0000 you can always add more opacity to black which is what we'll be doing. Okay, because that's a pretty heavy box shadow relative to what they actually have in their one. But if we did something like 05, this looks way more close to what they have. Okay, let's add an align items center on this just for fun. Yeah, this is looking pretty good. This gradient border, man, what is the strategy that people use for gradient borders? There's a number of ways you could do gradient borders. I've done gradient borders so many times in CSS
and it feels like I always dislike [music] the strategy because what you can do is you can have a background and then you have like a span on it. So you have a wrapper element is a very common way to do this. The way that I've always done this is with a wrapper. So I guess I am going to do a wrapper in my HTML.
I'm not talking about uh Kendrick Lamar here. Sorry for that joke folks. I am a father of two. Okay. I have a span. I hate this because I just did all this work and now I'm going to have to say, "Oh, dear God, Scott." Okay, I'm trying to go fast. I'm trying to go very fast. Very fast. Very fast. Very fast.
Okay, [music] so uh obviously that just totally screws it all up quite a bit. The background of the button is going to be a gradient. So, we will want to have a gradient for the background of the button. What other things do we need to have on the button itself? We'll want to have the font size. We'll want to have even like the color is fine to move on to the button itself. There we go. The border well the border will in fact live on the button although it's not going to be a border. The border radius will live on the button. The box shadow will live on the span but the inset will live on the span and the noninset will live on the wrapper. Okay. So, I should have done this from the start. I instead of being like, "Oh, I'll solve this later." I should have solved this from the dang start. Okay. Okay. Width will be on the button and then padding will be on the span. Okay. Why does this look so terrible? We'll need to give the spans
display block or they got to be inline block. It doesn't really matter. Maybe block. Why is there a border on Oh, cuz I don't have color defined on this. Okay, this is going to fix things right here. Okay, that gets a little bit better. Now, why is the first one so much worse? Is this for real? Let me refresh this. Why is the first one so much worse? Oh no. This one gets a color. This gets a color. That overrides all that stuff. Why exactly does this one not have a span in it? I didn't put a span in the first one.
What was I thinking? Okay, save that. Good. We do need to have the same border radius, I suppose, on the span. This feels wrong now. This feels very wrong because we have the padding on there. The button itself is having some default padding. So, we'll just say padding zero. Or is it because of the width side of things? If we give this a width, does that fix it? No, it doesn't. Let's do computed. The button has a two pixel border on it. Okay, let's get rid of the border. Okay, border none. Let's zoom in on these things. Of course, I've like ruined this whole thing by adding this.
What I don't understand is where this additional padding is coming from. We'll just say padding is zero. Do buttons have default padding on them? I guess they do. The only difference is is that when we do the gradient for this part, we want it to be reversed. We want it to start light and go dark. Start light, go dark. And how dark should it go? It should go much darker. Like that darker.
Like that. Really feels pretty good. The top one needs to be quite a bit darker as well. The problem now is that we're doing a linear gradient and we now have double the color. So, this all feels like you're having one gradient and then another gradient and since we're doing opacity here. So, that really screws me up for a number of reasons. So, we're using relative color syntax here to do opacity, which does in fact work decently well on a white background for these things. But if we do color mix, we do color mix and mix it with white. I've been for weeks here, I've been thinking to myself, man, relative color really rules compared to color mix. I have been reaching for relative color kind of non-stop. I think I might be wrong. I think in this particular case, let's do color hyphen mix. Color mix is just
something I haven't been doing. We're going to say in RGB, we're mixing the hyphen color and we're mixing white. So, that just mixes the two. What is the If we want to give this a percentage, how do we do that? And it looks like I seem to need to be using sRGB apparently.
And I think I need to say something like we're going to do 90% white here. Does that work? It works. Okay. So, this is already kind of solving some of the problems that I was having. And instead of doing relative color, which was a great guess and a great thing that I like to do, I can do color mix and I can get us Oh, is this is it's more subtle.
I'm I'm doing it way way too much. Oh my god. Zoom. What in the world? [snorts] Zooming in. Oh my dear lord. Okay, so now we have a gradient on the top, which doesn't actually uh that could probably be color mix as well. We do have a nice little thing here. What I'm noticing is that the color is looking pretty decent on these things. And overall, I think I kind of crushed this. Now, this one does look a little bit darker. Looks a little bit darker. And a little bit darker here, too. So, let's bump this down to 85 and let's bump this down to 95. Maybe even bump this down to 80 even and get some more depth in here. This looks pretty stinking good. I'm going to close this. I'm going to bump this up side by side. Let's get some interactive states in here and just like really make these things feel nice. So, if we want to hover on these bad boys, what would we want to have happen? So, if we were to say like we're going to hover on these,
what do you see happening? Like typically if a button it's maybe in a hover state it can like get lighter. So you could always say that color mix percentage is changing. Like for instance if we had the top purr which is going to be like 80%. If we have that top purr right here at 80% var and you'll say top I don't know why I [music] named it top purr. That's a terrible name but hey sometimes we just do name things like that. If we hover, we could say top purr is now going to be equal to 90%. And when we hover over these, they all should get a little bit lighter. Now, the big problem with this is that this is a a gradient and like transitioning gradient values is difficult. You could do that with at property. We'll see if this actually works. I I don't know if you can transition a color mix. So, we'll say add property and this will be top and I'm going to change this to hyphen top
property. The syntax is not going to be an angle. It's going to be a percent, I believe. Let's see. Percent. Is that one of them? Is percent. One of the things you can have as an at property. Just give me the MDN docs, please. Percent. It is percent. Percent edge. Inherits is going to be true. Initial is going to be 80%. And let's get rid of this one.
Okay. Now, no, doesn't animate. That's fine. We don't have a transition on this bad boy anyways. Also, I still use the word top per underscore in here instead of top hyphen per. It's always fun to change a variable name. And I'm just going to put a classic transition 0.3 sec ease all. Just do a a a blanket attachment of all here just to see if I can get any transition on this thing.
Yeah, I just don't I don't know if you can even with that percentage change linear gradient progress. So, I'm modifying the percentage value inside of color mix and [music] it is not animating or transitioning. And honestly, that's okay. I'm going to do a cursor pointer on this thing. I know I know that's controversial. People like cursor pointer. The shadow can get darker. This is quite a bit darker. No.
[music] Okay. And then when we click it active, we can just do a translate zero one pix. Got a nice little push in there. And for this one, the top purr will be actually getting darker when you click it. Let's do a straight up 80% when you click it.
Or is that where it is currently? It starts at 80. Let's do all the way down to 50%. When you click it, that's too much. That's way too much. Let's do 70. Perfect. It feels a little floaty because of that transition on here. And if that transition isn't actually doing anything beyond the shadow, we could say we want to transition the uh not all but box shadow. [music] Okay. So the the top little feels snappier. Perfect. I think this is pretty good. I think I crushed this. And I think it looks pretty dang good. And when you click them, you hover over them, they get a nice little state.
They get clearly highlighted here. Click it. Click it. Click it. Click it. Feels nice. I kind of like these buttons. Cool. The only thing I wish I was working on here would be the transition on that gradient. Either way, let me know what you thought of this speedrun. Let me top this off. Again, I probably could have finished this earlier, but here we are with 29 and I'm going to finish it just under 30 minutes. Knocked these bad boy buttons out. And again, they're nice and extendable because what we can do is just change their color. If I wanted to make these things purple, bingo, bango, we got a purple button that just works. Let me know how fast you got these buttons done. Post your links below.
Quote it with credit and a link. Quoting Syntax