Syntax Video
Gotta Catch βEm All! Recreating a Pokemon Ball with CSS
Transcript
Welcome to CSS Battles. Today, all three of us are going to compete to recreate this image with CSS. And we're trying to do it in the fewest number of characters. So, the person that has the fewest characters and 100% match will win this challenge. You all ready? I'm ready to capture it all. Catch it all. Capture it. I'm ready to catch it all.
Capture it all. Capture them all. Yes. Let's do it. Here we go. So, background should be this blue color. Let's just start there. And I'm not going to have a body element. I'm just going to target everything. Set the margin to zero and the background to be that blue color.
So, I'm looking at this right away. And I'm thinking let's use let's put a circle on there. And for the three layers, let's use let's use radial gradients. So, I'm going to give myself a paragraph tag. The I could see CJ talking in the corner of my eye. It's obnoxious. All right. I moved my my screen. I'm going to move him out entirely. Okay. So, my paragraph tag is going to be a width of 200 px and a border radius of 50%. Um, let's get the background color set there on the body.
Background. Let's get the background. Okay. Yeah, I'm not confident I'll get this done. And I I couldn't tell you why. I'm going to try an approach where I'm nesting elements. So, I have a paragraph tag here. And inside of that paragraph tag, this paragraph tag is going to be um let's do the ball. It's going to have a style. Oh my god, I can't even type. I got to tell you, something happened to me now. I'm like nervous on these things. The uh competitive spirit has hit me, folks.
And now I got to win. Now, we're going to need two semicircles. I think I'm just going to assemble this from parts. So, we've got a semicircle on the top and bottom, a rectangle in the middle, a circle in the middle, and then a circle on top of that. So, first, let's actually just get that yellow circle directly in the center. So, I'm going to have a P tag. We'll give it a C attribute, and then I'll target that element, and it's going to have a background of this yellow color. And let's just try it like 20x 20, probably 40x 40, something like that. And then we can give it a border radius of 50% should make it a circle. It does, but I learned from the YouTube comments that there's this unit called Q. If you do like one, is it like Q? I'm just going to stick with 50%. Never mind. Okay, here's how we're going to do this. We're going to do um [ __ ] Uh we're going to do a Pokeball. We're going to have it be red. We're going to say height and is
going to be 50 VH. It's going to be width of 50 VW for now. And it's going to have a background color of the color that we are supposed to do this as. It's going to have a border radius of 50%. Okay.
Um, now border radius. I was just looking up how to do linear gradient. I might have to might have to Google this. background white and height is 500 px.
The width is 500. Okay. So, let's make that 200 px. Okay. And let's put it right in the middle. Margin zero auto. Okay. And then we'll put it vertically in the middle. Line self center. Is that we have to go in the body line content.
Okay, good. So that's in the center. Oh my gosh, look at I freaking nailed the size of that. I just eyeballed it. 200 px first try. I'm so good at this. Okay. Wow. All right. That that was that was the win I needed. Um I'm seeing here the folly in my ways. This needs to be 65. 65. Okay. Wa. Um, which one's which?
Here is mine smaller. Mine is smaller. And then I need to absolutely position that. I I think fixed position is usually the way to go with these. We could like center the element and try to position it from there, but I always run into issues. But let's set everything to position fixed.
And then we'll give this a top of 100 and a left of 100. We're pretty much there. Let's go like left of 200 and a top of like 140 130 120. Okay. So, uh this is going to be the parent and the parent is going to contain these things.
These things are going to sit on top of it. And um this is going to have a background and instead of you know this, it's going to be a linear gradient. Linear gradient. And we're going to um start at oh man zero de. It's going to go zero.
Um there's so many of these linear gradient tricks in uh code golfing stuff that I have forgotten about them already, folks. So you're going to have to forgive me here. I'm going to have another P inside of this. This is going to be the P that is going to have a rectangle. This is the R. And um I forgot I'm going to put an overflow hidden on this thing. Instead of the background, um we're going to do a linear gradient with hard stops for the colors. Linear gradient. Uh red, white.
Uh let's put let's use the actual colors here. Okay, those are the three colors that we want, but they need to be hard stops. We're going gradient.style for Adam Argle. Thank you. Let's figure this out. It's going to But like I want like a hard stop. So if I do stop at 50% and then again at 50%, what is the CSS for that? To write 0%.
50%. 50%. Okay. So you put a you put a stop right there without the color. So if I put a 0% here and then a 50% here. Oh yeah, look at that. Okay. And then Oh, this one has to also be 40. This one, the white will also start at 50%. Okay, that makes sense. So, actually, we want to start at maybe 45 and then go to 55 to start the white. Oh yeah, look at how much I nailed that. That looks awesome. So, we want to do a red circle right behind it that's positioned in the exact same spot. This should come before it. So, the yellow circle appears on top. So, we'll do P of R. This will be our uh we'll do B cuz it's like a burgundy color. And we'll style C and B in the
same way, but B will have this burgundy background color. And then the width and the height will be increased a little bit. So, probably like 70. This probably would have been where centering would have come into play. But now we just have to tweak it with the top and the left. So I do a top of 120 and like a left of 160 and a top of maybe 115.
That looks perfect. Background of this. It is going to have a height of 20 pixels. It's going to have a width of 100 pixels. Um, and I don't know what what happened to the rest of my thing. What happened to the rest of it? Is it this overflow hidden? Did that goof things up? It's adding this P inside of it. Um, can I comment out?
I just goofed my stuff up so hard that it's gone. Oh, Scott, you didn't need this, man. Is it the linear gradient? Oh, it's the linear gradient. Okay, let's comment this out. Shoot. What's What's wrong with this code? Um to number percentage to number percentage to number. What is wrong with this code?
Okay, so we've got that. Now, let's get that rectangle. And then I'll have to look up how to create a half circle with CSS. So, we need a rectangle. Let's just call this R. And this will also come before E here. Let's set a width of like 300. And the height seems like it should be just fine, but we'll need to change the left to maybe be a little less. 80.
100. 110 was perfect. And then we'll need to change bring the width down. 200 170 180. Okay. So that's spot on. This is so dumb. So we're going to start at that color and then we're going to go to the same color. I think I had them swapped. I think that was it. I had them the the percentages swapped where we're going to say I think I had the percentage first and we're going to say 180 de. Okay, better. I'm going to submit this just in case. I cannot believe I wasted so much time on that.
The guys are always using box shadow. I thought I got to use more box shadow, but I think the gradient is the move here. Let's do the the one in the middle, the this uh yellow one. So, that will go on on top of it. What is the radial gradient syntax? Got to look this up again. Okay, so we want a radial gradient farthest corner circle at 50%. What the hell? Let's try try this. That's not working at all. I need to draw a semicircle in between the rectangle and the inner red circle.
I'm going to look this up cuz I don't know how to do a semicircle. All right, I found this blog. It's called unused CSS. The height is half of the width and then they have a border radius. That's the height height 0 0. So that seems doable. This P is inside of this P. If this is positioned relative, I could position this absolutely inside of this thing. Or I could just do margin margin.
And I could say margin uh 50% margin 40% margin 45%. There we go. The height is going to be something more like 25. I've gotten into musical theater mode right there. Okay. Why is the radial gradient not showing up? Does the gradient need to go first? It does need to go first. Weird stacking order. Okay.
So, this color here, this butter, and it's only going to go in 50px. And then we just go to transparent at 50px as well. And then the rest I take out.
Oh [ __ ] What happened to my other gradient? Uh-oh. Oh my gosh. What am I doing here? Yes. Okay. Okay. Okay. Okay. We're We're back. We're back. So, let's let's get ourselves the top circle. And this is going to come after the rectangle so it gets it gets drawn on top of it. But then the burgundy circle gets drawn on top of it. So this is going to go right here. And I'm just going to call this T for top. We'll replicate the first. Actually, no, we'll just we'll just style it all its own. So let's target T. It needs that background of this light red color. And let's set the height 100 pixels and the width to half of that. So like 50. And then we learned that the border radius set to half half 0 0.
We might have to use units here. Um, we kind of got it sort of. But did I do this wrong? So width 20 height 10. Yeah. So I I need to h I need to reverse this. So the height needs to be half. Yeah. Okay. This is the way to go. I have a half circle. I just need to make it bigger and put it in the right spot.
We're going to do auto. I want this to be centered and I want this to be, you know, like 150. It's closeish. 170 175. And then I I have an idea for this where we can say border and we're going to say border left. And that border left is going to be this teal color. And it's going to be border left.
And we're going to say 10 pix solid. Do I even have to say solid? But I guess I have to increase now the width because we're not using box sizing border box and there's some bizarre clipping going on. Of course there is. I mean it looks so right. Why is there clipping going on? It doesn't matter Scott. It doesn't matter. Keep moving. Keep moving. If I lose because of that. Um so be it.
Star Wars, right? I don't know. Cool. Okay. So now we need to position this thing. So, let's set a top of 100, 80, 70, 60, 50. It's really close. And then a left of 100.
It's perfect. Look at this. All right, 10 minutes left. We're looking good. I think I just have to replicate this. 35 35px. Oh, no. That's how 35 px is how big the outer one is. Remember 35px, but we're going to go 25 px.
Hell yeah. Okay. Okay. So, that's gradient one. Gradient two. So, now we need to make another one that is that maroon color. Maroon skid dunes. And what do we say that would be 35, right? That needs to go after the butter one. Hell yeah. Look at that. That looks so good. Without box sizing border box, I am a shell of myself. This looks good, but there is some weird clipping. Is it because I'm zoomed in? I guess it looks fine. Let's zoom out. A 97% match already. Good stuff, Scott. Good. Good stuff. I like that stuff. And then now, let's just have a pee on the outside of all this.
What? Mine is taller. Taller than it needs to be, but the arc and everything else is perfectly fine. I'm curious if we change like this one to like the second one to be like 190. What does that do? Or like 100. Oh, no. That's the top right corner. Okay, that means we could decrease the height more. Oh, but then that changes the arc.
Oh no. Oh no. Okay, that's fine. We just need to change these other values. Bring them down by 10. Like 190. Okay, it looks like we need to increase them. So like increase by 10. Let's try 210, 220, 230, 240, 250, 260. Oh, that's so weird. I probably need to look up what these values actually do. In in typical strategy here, I'm just trying to get something on the paper and then I'm going to worry about optimizing it because we have time here.
Um, I turned into Steve Urkel there for a second. Now, we just need to simply cut out these little end pieces here. So, now I'm wondering, do I just use a before and after? Before, after. Display block. Is it going to be less code to just put more elements in there? I kind of like doing it in one. Background black, height 10px, width 10px, top 10 px, position relative 100 px, 90 px. There we go. Okay, let's change the background. Hell yeah. You can't even tell. Okay. And then we'll just do the after. Probably 190, right? Yeah.
Um, and then top -10 px or margin top. I got it. That's it. Better be 100%. Woo. All right. Now, now my friends, we figure out how to make this as possible cuz I think we've got time left. You know what I might do because we only have 8 minutes left is go back to like the the perfect sizing or it had the wrong height and then just push just position some elements so that it hides that extra part cuz I think that's the only way we're going to get this perfect arc. So yeah, that's what I'm going to do. Um this is fine for now, but then let me get that bottom white circle and then I'll position some elements in the exact right spot. Uh so we also need a white circle. W will have the same styles as T except we'll change the background color and we'll rotate it. Background is white. We'll do a transform
rotate 180Β°. Yep, that flips it. And then we'll just change the top 200 150. I mean that's pretty good. That's pretty good, too. So, like I mean we could position it exactly and then we just we don't need this burgundy thing. We just we'll draw multiple of them.
Yeah. Honestly, that's that's perfect. And then I just need to draw the burgundy square on top of it. Why does inset never work in this thing? I feel like inset is broken in this. Oh my god, I'm wasting so much time. My circle's too big. I'm fat fingering everything here cuz I cannot type. Okay, last little bit here. I'm going to do a border. Oh my god, we got 6 minutes. I just wasted so much time blabbering.
Border and we're going to say 20 pix. Of course, it didn't work. It's going to make me type in solid. I swear. This is so annoying because now I got to subtract 10 by everything to get it to be the right size in the right place in the right thing. And it's now off by an endless amount.
What if we just change this to body? So just R is going to have a way smaller height like 30. And then we'll bring it down a little bit. Okay. So that's it's in the exact right spot. We now just need to change the height to be 20.
Yes, that seems to be exactly right. Now we just need little cutouts that are like the teal color. So I'll just add those on the end. That's still quite a bit of code. How do we make this smaller? Height. We can take the PXs off, right? Okay, that's good. I was at 600.49.
Taking that P those PXs off, does that help us in any way? Not really. Not much, man. I really should apply these styles not to the body, but to the paragraph tag. Wouldn't that be cool? What if I did instead of that I did a box shadow of that color and then 00 0 and then 10 pix for the spread.
Of course, that's it. It took 1 second to do that instead of trying to fumble around a a box shadow or a border. Yeah. 5 minutes left. I think I can I can get these last two elements. So, let's just call this P of O cuz it's the outer element. Let's copy the styles from the rectangle, but then O, it's going to have a background that's the same as the teal color. Well, which it gets by default cuz we set that on everything.
We'll just change the width. I don't know, like 30 or so. And then change its left value be much farther over. So, like 90, 70, 80. That's perfect. Okay. And then we can just box shadow it to put it over on the right side. Oh, I got width on here twice. You can take that off. I'm just going to start putting everything on one line now. Can I just use a CSS minifier?
Let's see how much smaller this makes it. Oh, hell yeah. Where's my before and afters? You strip my before and afters. 99.9% match. See, this is what I was worried about. Like, holy crap. What am What am I missing here? 99% match. Okay. to prevent myself from running out of time from optimizing in some degree. I am going to start to optimize now in an in an attempt to at least save myself some pain and humility when uh we inevitably end this.
Like maybe we could push the this shadow off like one more pixel. No, that's not good. That's like that's worse. Like I thought my my angles were like perfectly right. I guess not. 99.8. So, that was a bad move.
600.56. The bet better go up. 604. Not bad. Not bad. I got some more spaces here. What happens? Can I get rid of all these spaces? Shoot. No, you need some of these spaces in the syntax, but I don't need the spaces when it's right here. Okay.
What if instead of we instead of doing VH we actually did something like the pixel values like 200 pixels and of course the first number I guess is somehow magically right. Um is there any shorthand background? Um Scott did like an inline a bg inline BG HTML inline BG. What the hell is this?
Nah, screw it. I'm not going to mess with it. Should I mess with it? Shoot. How where did all the time go? Optimize. Optimize. Oh, can transparent be replaced with a hex code that is transparent?
3 4 5 6 7 8 9 10. I can save one character. Ah, guys, how did I goof this one up? What? Oh, is it over? How'd y'all do everybody? I shocked myself with this one. I did great. When you guys were talking, I was like googling how do you do radial gradients? I killed it. I nailed it with the radial gradient. So, I'm really excited about my my solution here. I'm less excited about my solution. So, I will go first. Uh I I did not win this cuz I already heard you mention what your score was. box sizing border box to me like screwed me cuz it's like I have this little sliver here cuz I was like just having to deal with the you know what is the width plus the borders to get it all centered. So I did get a 99% match color.
Yeah, I used BG color on the body align content to get everything aligned. Um I did a div and then inside of that div I did a paragraph tag for this horizontal. So I did a horizontal with two borders on it and then this is a linear gradient on a on a div. So, the this is a linear gradient on a div for the red to white and then a circle with just a box shadow on it. But I I I got to tell you, I was so frustrated by the border box stuff that I spent way too long on it and then uh was just trying to slim down my code.
I'm just annoyed that I didn't get to 100%. I'm I'm so Yeah, I'm I'm super annoyed. The diff is really clean. It's just it's just so ever so off. I was debating this. Is it Is it better to do inline styles versus a style tag? If you if it's non-re repeated then yes. Okay.
If it's repeated style tag is body CJ's muted. I was I was going back and forth whether to try to do it inline or not. Yes. And I ended up just going style tag. I would say so you need to count the characters. If you do style equals quote you have to do that for every element and that's going to be more than if you just had a single style tag with like an attribute selector.
I think I did a pretty good solution overall. just didn't get there. Surprisingly, I beat Scott by 0.01 points. No, I got a 447.26. But but I I I don't know what's going on today. Like these diffs are really killing me cuz like it's perfect except for like tiny tiny little bits and I have no idea what I could do to get it even closer. Yeah. 99.9% match.
Oh, so you did a lot of P tags or you did several? Yes. So everything's a separate element. So, I used I I looked up uh there was a blog I found on how to do like a half circle and it's basically you specify width height is half the width and then a border radius that has 200 pixels for the for both values that is the same as the width. And this gives you half circle.
But you could have just done one singular circle with a linear gradient. Sure. I'm not that smart. But yes, that's that's a good thing. I didn't think of that. But yes, that would have been less code, too. I use the new um align content center on the body, which is the move. So, you can vertically center things in a block.
I'm going to start reaching for that cuz like everything here is fixed position, but I think for whatever reason that just like it's just off slightly for some reason. I don't know. All right. Read them and weep, brothers. Yeah, you got 100%. I got you. 100%. Nice. three characters less than CJ. I use a radial gradient for everything.
Um, so it is a or sorry, it's a linear gradient for the Pokeball. So it's it's red, darker red, and then white. And then it's a two radial gradients for the centers. Um, and then two little before and afters. I was I was going to use another stacked gradient that just covered up the edges.
Mhm. Um, but I I was panicking, so I ended up just throwing a before and afters on there, which I don't like because it's it's a lot of code to to do content display block on them. So, I need another move for that. But got a 100% match, which I I shock myself. Usually I'm pushing stuff around and adding pixels here and there. And this one finally snapped into place.
Heck yeah. Great solution. my the my three characters lesson CJ is I was trying to find out like what's the what's the shortest possible way to do transparency I was thinking like rgba with a zero the word transparent is one more character than the hex code with with that on it so those two plus one other oh I have a space right here there's a few more things you could like you can remove the last curly brace and the last style tag you can also remove that closing Closing P tag.
Yeah, you can use that. Yeah. Yeah. Okay. And get rid of the closing P tag, too. Closing P tag. You can get rid of uh the last semicolon in any style thing. Um the very last one. Oh, look at this. I'm at 450. Yeah. Yeah. It sucks that CSS variables are so long. Hey, like it almost never makes sense to use them. People are always saying in the comments to use them, but it's like even a one character CSS variable is var parenthesis hyphen characters.
Yeah, there there is no there is no best use case unless it is transparency or something, but those hardly ever come into play. Great work, Wes. That was a sick solution. Wes with his first victory. Wes, I've been it's been too long and I appreciate it all the comments. I like need to study up on a lot of these stupid tricks that you guys use.
I wrote myself a cheat sheet of my own personal tricks. Really, but I just don't have enough time to look at it because I'm always struggling to finish. Now, that was awesome. Uh, if I'm going to lose to anybody, I'm glad it's Wes. Sorry, CJ. You just win too much. Love to see it. CJ needs to be knocked down a peg or two. Yeah.
Uh, what a rousing CSS battle that was. If you like this, let us know. If there's any CSS battles on CSS battle.dev you want to see us compete against each other for the smallest score, drop them below. We'll take them on. And if there's anybody you want to see come on and challenge us, uh maybe somebody who can actually show us a thing or two, let us know. We will uh absolutely make that happen. As always, we will see you in the next one.
Quote it with credit and a link. Quoting Syntax