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

Syntax Video

We Recreated Donkey Kong in CSS (Battle Royale Style!)

Chapter 1 00:00

Transcript

Welcome to another CSS battle. Wes, CJ, and myself are going to be duking it out by recreating a Donkey Kong level in CSS. We got 15 minutes on the board, and whoever can get the smallest, most accurate CSS code wins the game. Who's going to do it? I think we can definitely use box shadow for the pinkish purplish line here. So, we have one pinkish purplish line with border radius, and then we box shadow that to get this one down here. I don't know if you can use a transform on a box sh. I don't think you can transform a box shadow. So maybe this one is like a after selector to be the exact same thing. And then I think we can recreate these white lines with like a single div and then a bunch of box shadows to put it in three other places. That's that's my strat. All right. Yeah, boy. We got 1 2 3. These are the same. That could be done with an ID. One, two, and this could be one single line. So 1 2 3 1 2 3. So we can have six paragraph tags, I believe. Um, I don't know. Let's just do

let's Come on. Okay, whatever. Yeah, let's start off with the div and then inside of that let's do three HRs. One, two, three. Okay, now let's get the colors in. So, background is black. Let's go. I'm going to style everything to remove margin and set initially the background of everything to be black. The HR is going to be background pink.

Height 20px. Oh, got take the border off. It's not worth using an HR if I take the border off. So, what's the shortest block level element? And then it needs a border radius. We'll try like five pixels. So the width of the screen is 400. So maybe we want like 250. That's possibly it.

And then the height is uh really small. It's probably like 30 pixels, 20 pixels, something like that. Okay. Border radius is going to be something like 20. Okay. Width is going to be Ooh. Ooh. Ooh. Ooh. Ooh. What if we did something like 80 VW? That's like a much shorter value.

I'm Look at me. I'm thinking about code golf now. That's a much shorter value. Um, border. All right. Now, we do border radius 50px. Okay. The height of this is probably closer to 25. Obviously, what would work best here would be a style with a display flex flex direction? Like, is this actually short to do it this way? I think I'm just going to use offsets like or like margin. And so if I give the body a uh margin left 30 pixels and then a uh margin top of 100 pixels too many 50 40 50 Yeah. So that's that's exactly in the right spot and I I nailed the the height there. So justify content is going to be center. Justify content center. No, it's not. Man, I

would really love some dev tools right about now. I wish I could use dev tools. Throw some debug in here. Boom. That is correct. I need to height 100%. Boom. Okay. Get rid of the background red. I'm cooking with gas now. I can't even tell where my Okay, mine is a little too far. So, we need to go less. That's not enough. We go more.

That's not enough. We need to go more. Yeah. So, 17 pixels from the left, 45 from the top. And then the width needs to go up a little bit. Let's go 300. on each HR and just say margin top, right, bottom, left. Okay, probably closer to 30. Okay, now they are just a hair too spread out. And one thing I don't know is that is that because of margin? Like if I have margin margin zero on these things, is that the thing? What is the default margin? That's not something I should be asking. I know what the default margin is. Why do I need to ask that? Oh, that's a little bit long. 300 299. Okay, that's an almost an exact match. Ooh. Oh.

Oh. Yes. Okay. No. What's the I'm I'm overthinking the optimization here where Let's just give everything an X. Wait, can we just use an X tag? It's not valid HTML, but who cares, right? 1 2 3. Yes. no X offset and then like a 50 pixel Y offset and then it should be the same color. There we go. And we just need to push that one down to the bottom. So, we'll go 100. That's perfect. Some of these guys, they don't think about using rotate as a uh property. They just don't think about it. And this is what I was saying, like I don't think you could do like a transform on a back shadow.

Rotate's a great property and it's totally supported now. So you can use just straight up rotate. You can do that and nobody's going to stop you. I got the pink and that is perfect. HR X 1 2 3. Okay, there's going to be no margin on those. Now I could obviously do these with after tags. I could do that. I could do them with something in line. I could have a P after, a P after, and a P after. But honestly, I don't know if I want to do that. Maybe we only add the box shadow to one of the lines and then we have a second line that will be the center. So, I'll call this one like C. Okay. So, that middle one is C. I'm going to do what Scott did in the last one and just start it doing the inline on each of them to overwrite. I think that's a good idea. Maybe I got 8 minutes left. Should I should I try get them near the middle

of the page? background is going to be uh just pound fff. Let's not keep these. Yeah, let's save some code right there. And width is going to be I believe 20 pixels. And the height is going to be different from all of these, but I will define a default height on one of them that's like 100 pixels. Okay. And did I just put this in there? Bro, I meant to do that. Let's just transform it. So if I do a transform rotate 5Β° 5Β° -4Β° that looks pretty good. We just need to move it up a little bit.

Justify is left to right. I always think Judge Judy doesn't justify or she does justify. So justify content stretch. Okay. Negative 1. Oh no, not not X. It's going to be Y cuz we want to move it up in the Y. Yeah, that's closer. So like negative, that's almost exact. I want to see if I need to do Z-index if I move this before here. I don't. Perfect. Nice solution, Scott. Very smart. Instead of doing top, we could do margin. And margin can be 20 pixels. 0 0. I think that might be faster than doing a top left, bottom right, whatever business. I don't know if it is or not. But listen, I'm just going to get this down on paper. Seven and a half minutes left. I think I think that's going to have to do for the center section cuz it's a little bit off on the left, but decent enough. So, we can remove that background color. Now, we need to work on these little white columns. So, top right, bottom left. And

so, if we do margin right as in -100 pixels. Okay, it needs to be more than that. -200 pixels. There we go. I mean, you could also say margin left and not have a negative there. So, like I suppose that is a better solution. Man, it sucks not being able to debug this with the dev tools. If I don't need any of these now.

Okay. Place items center. Yes. Okay. There we go. Uh, do we need that? No. Do we need that? No. Okay. And we're just going to move it to exist right here. And then we're going to box shadow everything else. So, we'll give it a width of 10 pixels and a height of 30 pixels and a background of white. And now, what's super curious here is that this one is no longer below or above things. Instead of zero pix, you just say zero. Yes, Siri. Okay, only 5 minutes left. I need to get these little white columns on the screen. Why can't I see it? Okay, position fixed.

Width 10, height 30. Maybe minifying it has messed me up. Position width. Yep, that's supposed to be a semicolon. My goodness. I don't know if anybody else is using margin. Margin feels like such an odd choice here. Let's see. 100% 100% 100% 100%. Let's go. 100% match 600. Let's go. I am not slowing down here. I got five whole minutes to optimize. Okay, let's get the height. I got to move it down a little.

Um, shoot. Four minutes. Let's move the the white things now. All right. So, it's the first white one. Oh, we got to rotate them, too. Uh, I'm going to try to move it to where it needs to be. It needs to be wider. 20 pixels looks good. And like a height of 40 pixels probably looks good. Move it down more. Yeah, that's about it. So the first white thing style equals margin- left. Okay. So I'm going to hit enter and it gets me what? We'll see.

60287. And what was it before? I I guess new high score. Okay. So new high score. That means translates less characters here. And maybe it needs to little bit be a little bit higher. Yeah. And we can remove the Z-index at this point cuz it should be underneath. Oh, well actually we won't remove it. We'll we'll set it to like negative one so that way it's underneath the levels. Second one goes all the way to the end 300.

Okay. But then also the scale Y 200%. Let's give the Z-index of everything. Okay. 3 minutes left. Zindex of everything will have zero. And Z-index really messes this up. I think instead of z-index, we can just put it as the last element and then it should get rendered should get rendered underneath the lines. Margin-top negative 20px. Oh no, that's going to change the thing. I need to use a transform. Don't need that scale. Do need the translate Y. Okay, I just want to kind of get rid of the lowhanging fruit first here, like eliminating spaces, that kind of stuff.

The thing is is that all of these values could probably be done with like VH uh and stuff like that. You're going to translate this like negative VW 100. This value right here is shorter. Is this going to be harder to figure out?

Absolutely. But can I do it, folks? We're going to have to see. Man, only 2 minutes left. Okay, I think I'm just going to try to position it perfectly because it's overlapping a little bit. We're not going to get to 100% match, but if we move it down that much, it's an exact match right there. And then we can add a box shadow to just like repeat it. Let's move this down 10 20 35 px 32 px. Let's diff it. No, that's too much.

210. Only a minute left. If I can just position this, it'll get a pretty good match score. Woof woof woof woof woof. I got a minute. Okay, so let's first copy this. Let's paste it down here. Comment it out. Let's copy this and we're going to just start goofing with this one to see if we can I don't know if this will be shorter. Um we only have 30 seconds left. That should be enough to put the one on top of it. Right. Uh that looks good, but it's not like lined up. So the diff is going to kill me. Yeah. No Y offset. Yeah. Okay. Much closer. I only missing one with 8 seconds. I don't I couldn't do it in 8 seconds. But 7 seconds. Can I change the width of it?

Okay. Time's up. Oh well. Submit. I'm not confident in my abilities anymore, so I think you guys are going to crush me. I love to hear that. Yes, I got a 99.4% match score of 587. Nice. Basically, I just have one div for the top level and then I used a box shadow to repeat it as the bottom and then I have another div for this center area and then I used a transform, rotated it 4Β° to get it slanted. Oh, smart. So, you did this with just four paragraph tags.

So, two paragraph tags for the three levels and then one paragraph tag for a column and then I used box shadow on this column to repeat it multiple times. So, one column here, box shadow to put it here and a box shadow to put it here and then I didn't have enough time to put the box shadow there. Crazy. That's a crazy solution, CJ. That's That's really good. That's impressive. You guys are talking like you like you beat me.

Mine has so much more CSS. I did the same thing I did last time where I just kept You can get rid of the comments, Wes. The comments doesn't matter. Yeah, it does. It does. It does. Okay, let me submit with the comments. Like 20 points. Uh oh, you're right. It was 20 points. Still only 194 though. I'd started using grid and then it wasn't over overlapping properly. It's so frustrating that you can't inspect element on it. Oh, it's so frustrating.

It's a close match, but too many characters here. Yeah. So, I ended up with 457, but I my final score was 605 cuz I had a 100% match. So, mine was somewhat lowi. It's hard to tell. Killing it. Yeah, great work, man. But I did a div wrapper. I just made that wrapper a flex container. I flexed these three vertically. I rotated this one. Um and then these are just three eye tags.

I was just trying to use small tags. Oh, eye tag. Yeah. What what's funny about this is that so I had gotten this pretty much done at like 603 and then I decided to change this translate to use VW instead of pixels and it it saved me like two points here at the end and then I I tried to do it on some other stuff and I totally broke my my thing but I got it back. I was also having an issue with Z-index. I couldn't get my columns to go underneath the levels for whatever reason. Let me tell you how I did that.

I just put the eye tags first and then the paragraph tag second. Use the platform. That's getting into the the optimizations part of it cuz I had five I finished with 5 minutes left. So I had five optimizes. Holy Scott killing it. That's amazing. 100%. That's so impressive. I can't believe you. I just keep pushing around pixels. I got to stop that. But if you want to see more of these, let us know. Leave a comment down below. Cuz these are certainly a lot of fun. Even if my ego is very bruised after that, I uh I I will come back with a vengeance. I'm going to come back with a win.

Quote it with credit and a link. Quoting Syntax