Skip to main content
View on YouTube to comment and like!

Syntax Video

Recreate PACMAN with CSS?? CSS Battles

Chapter 1 00:00

Transcript

Hey, what's up? It's time for another browsing CSS battle. We are going to be creating a Pac-Man image here and we're going to be doing it in 12 minutes or at least attempting to do it in 12 minutes. So, guys, are we ready? Yeah. So, what are we doing here? We're doing shortest amount. Shortest amount, highest score.

So, shortest amount and the closest. Ready? I'm ready. Yes. All right. I'm not going to goof this one up. I'm going to give myself a Pac-Man. Ah, damn. I don't have my EMTT every single time. So, I'm using this little BG color trick. I learned it from the FAQ. I'm trying to learn things from the FAQ. We have several shapes here. Uh, one of which can be box shadows, three circles.

Let's do a a Pac-Man with a P with an attribute of P. And we'll also have a style tag. Actually, since this is just I don't know, is that shorter characters? I don't know. I'm not going to worry about optimizing until the end. Okay. Okay. So, immediately let's just make the background black. So, I'm going to target everything. We will do uh background black and also set the margin to zero. Okay, that is going to be Pac-Man. And then we want dots and we want the ghost. Now, we need some style tags. body background is black. Okay, I'm going to place everything first and then worry about getting it all right cuz I always goof that up. Background, um, it's this yellow color. There's no possible way of shortening that. It is

heightwise, I don't even know. Let's say 40 30 VH. Let's say 32. You might be wondering why I'm doing VH for this. VH is going to be shorter than 100 pixels cuz it's definitely more than 100 pixels. I mean, maybe it's not. I don't know. Like I said, I'll optimize later. Make that a little yellow thing. So, we use this attribute selector here. It's much shorter. Let's go ahead and remove all this stuff and this so we can stay as short as possible. And then Pac-Man is going to have a background of yellow.

And let's give him a width of let's try 100 and a height of 100. Uh, that's too much. Let's try like 50. Maybe that's it. And then let's add our border radius. I know we can do 50%. That's three characters. Three characters is fine. Maybe we can get it in two characters. Like one view width, nine view width. Yeah. Yeah. 7 VW is three characters. Wait, that's the same amount. 50%. It's more clear. Okay.

So, we have a circle. I'm using attributes here instead of selectors. I'm not worried about uh getting this too short right away. I just want to get them to show up on the page. Okay. So each of these, can we grab all the divs?

Width 100px, height 100 px. Okay, then we will grid template columns 1f fr 1f fr 1f fr. Okay. Oh, it's got to be height 100%. Oh, that's looking good already. Honestly though, instead of doing position fixed, uh, let's just create a container that has Pac-Man and the dots and everything inside of that.

That that actually should make things a bit easier. So we'll have a P with an attribute of C. That's going to be our container and that's going to have Pac-Man inside of it. So let's say the body is a flexbox. Actually, if I do a grid and then place content center. Yeah. And then just give it a height. So the body has a height of uh 100%. Okay.

I'm going to add a display flex on here. And we're going to have this be align content center. Justify content center. We'll have a gap of let's say 40 pixels or something. You know, whether or not this needs to stay like this is yet to be seen. Okay. So, we have this P. We have uh with another P with a D. PD. So, we got a P with a P and a P with a D. And we also need to justify content center.

justify items. Okay, close enough, right? Let's add a container for the three dots. So, do P of D. Let's actually do P of Z. That's the container for the three dots inside of here. And then that's going to have several uh P of D's inside of it. So, we'll have three P of DS. Flex. Oh, man. Why am I blinking on that property? To get everything align items center is align items center. No, man. Flex uh flex. Dear gosh. First of all, Pac-Man is going to be border radius 50%. Okay, the dots. Uh, let's worry about that later.

I hate that this formatting is so effed up. Give me my auto indent. Um, border radius 50% 50% 0 0. Okay, 8 minutes left. I'm have a lot of code and not a lot on the screen. Okay, so P of C. Um, we'll give it a width of 10 and a height of 10 and a background of white. Okay, there are they all on top of each other? Oh, no, they're all uh beside each other. So, we need to So, this should actually be P of D. Yeah. So, there's three of them.

Great. I think I just have to absolutely position all the stuff. That's what we're going to do. One dot. That's great. Now, let's make our last guy, which is uh P. And this is going to be a V for villain. I don't know what these guys are called. He's a ghost. But, and I got a P with a D, a P with a P, and a P with a V, I guess. Okay. Not intentional, folks. This guy needs to be quite a bit different. And you know what?

This is going to drive me nuts because you could do this so many different darn ways. Um, but let's just do it as a rectangle. We're going to do a height of 20 VH and a width of uh 20 VH for now. And we're going to do a border radius radius. I cannot afford to not finish this. Let me get rid of that. And then we'll just absolutely position Pac-Man.

I'm going to have to fix position every single one of those dots. Only five minutes left. This is not looking good. Okay. Uh let's bring it up a little bit. Like 130 120. And then we'll give it a left as well. Let's do 40. 50. Almost there. So probably like 55. It's not quite big enough. Maybe 60. Let's try a width and height of 60. Okay. So it's looking better. It just needs to go up a little bit. Yes. Okay, that's it. That gives us our yellow Pac-Man circle.

Okay, that seems to be the right height. The width is slightly shorter. Hey, probably 70. Yeah, 70 pixels. Okay, we might not even need to do gap here if we can just do this all with the margin, which we're going to have to do anyways. So, if we need to do margin anyways. Oh, man.

Scott, proud of you. Okay, I'm so I'm so I'm so proud of me. All right, I cannot Is that Drake? I hope that's not Drake. That song is Drake. I'm going to be upset with myself. Oh, 5 minutes left. I'm not going to hit this. H. Maybe we just want margin dash left. We could just bump it over. Yeah. Okay. Now, let's position these dots. Only 4 minutes left. This is not looking good.

So, we'll give it a top of 140. 145. A left of 200. It's too much. 100. 160. 170. That's about the right spot. Let's just make these all uh circles.

So, we'll give it a border radius 50%. Move it over. Oh, that looks good. Look at the diff on that. Close enough. Okay. Now, let's work on Let's get the ghost. 55 56 57. Yeah. Okay. Height 50 40. No, 55. Okay. Perfect. That's the right size. So, if I do now a margin left on this bad boy and have it be Does that push everything else off? It does.

So, this is going to be like a lot of finagling here. 3 minutes. Are you kidding me? Oh my god. Translate. And we'll have um -10 pixels. Uh uh uh. Okay. 14 pixels. Translate. Only 2 minutes left. I'm going to create a red circle for the ghost and that should at least get me a higher score. So, we'll create another P of G. That's going to be our ghosty. Let's actually give it all the similar styles of Pac-Man. So, we'll do P of P, but then we'll just change the background color. So, P of G.

We'll give it a left of probably 300 and then make it that red color. I will be shocked if any of these other guys get this done in time because holy cow, this was not enough time. Man, I'm so good at this. Okay, how do we do the cutouts? Maybe we'll do an eye with a cut inside of Pac-Man. Um, oh, we got a relative Pac-Man himself.

Man, I actually got the size on these kind of like dead on first try. That is absolutely incredible. Translate 14 pixels on the V. Okay, man. I'm watching this clock here ticking down 2 minutes. Woof. And watch this trick. So, border 50% solid red. No. 50px. We don't want a width or a height. Oh, there we go. So, how big is Pac-Man? 60. So, if we put a 30 pixel border on there and we make the border transparent and then the border-ight is going to be black. Uh, border write color. See, if that's red, it's already cut out. But if I make it transparent. Oh, we don't want the background. That's why. Yes. Okay. All right.

Good. Oh, that's not good. Okay, whatever. I shouldn't be doing that. I'm slightly concussed. I mean, I only have a minute and a half left. Let's just make a black box that rotates right on top of the uh Pac-Man. So, uh, let's make one more div that has a P of B, cuz it's the black box, but it'll also be positioned in the exact same spot as Pac-Man, but P of B. Uh, we'll set the border radius to zero. Give it a background of black. Uh, how do I cut this triangle out? You could do it with a box. You could do it with Oh man. Oh, how do you get this triangle out? 46 seconds.

Um, what do I do? And like will this actually Oh my god. 40 seconds. So transform rotate 45 degrees. Move it more to the left. H. But then it's going to cover up the square. Oh, let's just try. I have 30 seconds left. 60. So if we go like 80, 90, 100. Yeah. Does that do it? We have a Pac-Man with 18 seconds left. Sweet. Okay, guys. We're cooked. I feel like I could use more time. Do you want to do a few more minutes? Um, I I would do a few more minutes because then I would have time to uh finish and get to 100%. Yeah. Yeah. I got some cool tricks. Let's Let's do a few more minutes. How many more? Five or I don't care. I'm working.

We've been given extra time. So, a 99.1% match. I think I probably could have taken the V on that one, but we'll see. Okay. So, let's work on this P. I can have it be background 00. I can have it be a height of something like 50 pix. a width of 40 pix. I'm afraid that CJ is going to win this again. Let's actually work on the red square first. So that way he has a little skirt. We're gonna have the ghost skirt. So P of G of S.

We'll have border radius of zero. Bring the height down to uh 100. No, that's way too big. 50 pixels. Probably like 30 or so. Yeah. And then just bring it down. Watch this little trick. See these little spaces? Font size zero. Puts them all side by side. Beautiful. Margin-top 10px. There we go. Let's do that. 30 40 50 40. Okay. Oh, can I just rotate them?

Oh, you can't rotate something that's inline block, can you? Oh, it's cuz it's 45Β°. You can rotate them. Oh, yeah. I don't need the border trick. All right, screw that. We're going to rotate it 45 de. And then we're gonna You could do a left of negative 40 pix. No, you could do a left of 40 pix. Uh 80 pix 100 pix. Oh, come on. I'm just shooting in the darn dark here. Let's just go with W. So PG of W will be that first black box. Actually, we could if we give it PG of B. Now it will be a black box like this one here. All right, I got that done. I'm working with this negative view. And in that in that regard, I can do the same thing with another one. And this way, I can at least get a 100% match on this bad boy. And again, we're going to have it be white. We're not going to have it be 50 pix. We'll just

have it be 10 pics this time. We'll have it be 20 pics this time. We'll have it be 20 pix this time. the dots. Can I put them up here? Okay. Font size 20 px 40 50 60 70. Okay. Why is it so high? Okay.

So, let's get rid of that background black and then just get it in exactly the right spot. 170 180 180 is it? Okay. With a minute left, we have one one little skirt. We're going to do 51 52. This is going to be color black to get this on here. And then we're going to do a box shadow on this bad boy. At this point, I should just add classes. That's perfect. We have 30 seconds left. I think I can do I can do the last one. Yeah, plenty of time. 0 0 0. That didn't do anything. With 12 seconds left and we can get rid of one character there. Two characters. Can we just add spaces? What are the chances that the spaces work? No. Um, shoot. All right, let's see what these hosers have to say. How'd you do? I got uh such a kurfuffle at the end on mine. I swear I don't know what's going on. I did box shadow 15 pics 0 0 and then the color and it's just noting showing up. Where is

it? Oh, I found out what's going on. I just changed it white just to see where it went because it was a square rotated. When you do box shadow, it's like putting it down here on the hex value. Oh, yeah. Your origins are all flipped. All right. So, it looks good. Yeah. In this case, I didn't worry about doing it like shorter than normal cuz I always fuss on that. I I did do the like attribute trick, but like it 99.7% match and like my dots are so far. But I just panicked at the end and I literally just used a Unicode dot. Um, but for the the cutouts on here, I used a um the border trick where You you put four borders with the zero width div and then they they angle in. And on this one I just used three. Can we see that element? Can we see that triangle code? The other one. Yeah. This is a cutout.

So border white. So if I make that red. So you see that's the cutout. So you made a whole element that did it. Yeah. Nice. I'll I'll I'll share mine. So yeah, I did uh largely the same thing as US, but I did it with only five elements here where I have the I have the P, I have the D and the V. So we have a Pac-Man. I got the P, the D, and the V.

The Pac-Man was just a circle. And then I did the box, which is a allin line, just a rotated black square. Nothing crazy. I was doing the same thing with this one. And I was going to rotate it, but you can see like at the end here when I did that box shadow rotated, put it down here. Oh, and I just ran out of time. The dots is just a circle and then I used margin to get the spread. So I did flexbox on this, but then because this is a box shadow, I did uneven margin. So this margin and this margin being different instead of using gap.

Yeah, I could not think of a block level element that was one character. the paragraph tag. We do it every time. Are you not paying attention every time? I've been using dibs like a sucker. All right, CJ, give it to us. This is what I got. So, I got 100% match with 526 characters. A lot of items. Yeah. Yeah.

It's not It's not beautiful. Um, it's a bunch of ab fixed position elements cuz I was going down the path of should I like flex the body and then put everything in the center, but then I couldn't position things right. So, I just backtracked and fixed position everything. But I have all these extra attributes so I can reuse some of the styles. So, Pac-Man is P of P. And so, that's that yellow circle. Yeah. And then P of P of B. So, if we look at B, this is just a black box that's rotated 45Β°. But by using P on there, it can reuse the uh fixed position left and right. And then I only have to specify left. So And you took the pixels off again. Why do I forget that move? Yeah.

So I don't have Yeah, I don't have px anywhere. I forgot that, too. Oh, man. And then I did the same thing for this over here. This is a red circle and then three black rotated uh rectangles. And so I got really creative with the extra attributes cuz each one like reused the the all the CSS of the previous one, but then I needed more CSS, so I just added an extra attribute. Oh man, I could like modify that one property. Can I just say how infuriating it is that I don't have all my editor like shortcuts and stuff.

Part of this is so hard. When you hit enter in like a CSS, it like indents it sometimes. Drives me nuts. We need like um prettier running on this. Oh, totally. Darn CJ, I I was hoping to tie you back up. Uh, now CJ, I got to win two more now to get ahead of CJ if we're looking at these rankings. I was getting worried. The timer was getting down and I was like, am I going to be able to do this? But yeah, pulled it out. Yeah, that was a that went fast. That time went way too fast. Man, that that goes so fast. Good job, everybody. That's all we have for today. Thanks so much for tuning in. Make sure you like like and subscribe. We'll see you in the next one. Peace. Peace.

Quote it with credit and a link. Quoting Syntax