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

Syntax Video

CSS Battles! Who can recreate this with CSS?

Chapter 1 00:00

Transcript

What's up everybody? We got another CSS battle for you today. We're going to try to replicate this and see who can do it in what is it the the least amount of code is is how and and the accuracy is how your score is calculated. So, are you guys ready? I'm ready. Yep. All right. Here we go. I'm not going to goof this one up. So, first of all, style tag. Oh, stikeke. The body is going to be background this color. Let's start off with that. All right. We're in good shape already. So now I need three divs.

This looks like a bunch of rectangles. So we're going to start there. Uh let's just go set the background to uh blue. And I guess we'll try to use this trick here with like BG color. I'm using this body bg color trick. I can do this in let's see a couple of paragraph tags I think. So, we're going to have P and we can just have this P A and then I'm going to have P and we'll have this PB. A I'm going to use a P tag as 1 2 3.

The P tag is going to have a background of EGB 850. We have the background as blue. Now, we need a rectangle. So, we'll use a P tag with an attribute selector. I'll just use X. So if I want to style the element with the X attribute, I want to give it this background color. And then we'll give it a width and a height. I kind of want to turn the margin on everything off cuz you can see that it I mean cuz I'm probably going to fix position these. Let's Yeah, let's just do fix position and get it from the left hand side in the exact spot first. I'm going to target just the A. I've learned some lessons here. People in the comments have been giving us tips and tricks and I'm learning them. So, we're going to say this thing is height 100 pix.

I know that you can ignore the whatever uh stuff, but I am actively trying to get this done first and foremost and then optimize later. Oh my gosh, I'm like actually nervous. Should I be doing what CJ does and just put it all on one line like a madman? Okay, we're going to display grid. Grid template column. No grid gap 20px.

Okay. How do I get the height on these paragraph tags? Set position as fixed. This will have a top of let's say 20 and a left of let's say 50. So I just want to get the top right corner perfectly aligned. More from the left.

Yeah. So 110 from the left including its margin. And then from the top it's probably like 15. Yeah. So that's perfectly aligned with the top left corner. Let's get the width exactly right. We'll say margin top is like one pix here. U margin top two. Margin top three. Why isn't this margin topping?

Oh, okay. There we go. And the width is now a problem. So we'll say 80 pix. We'll say 60 pix. We'll say 70 pix. Boom. Perfect. Dead on. All right. Now we're going to do a box shadow on this thing. Justify items center. Okay. Align items stretch. Oh, this needs to be height. Oh, can I just do this on the body? Let's try. No, that didn't work.

Abort. Now, let's get the exact height. Try 100 and 40, 50, 60, 70. Let's try a height of 100. That's too much. Height of 80, 70. Oh, yeah. So, that's exactly it. This is our inner rectangle. And this is gets repeated for every single one. So, let's just get this repeated three times. So, we've got the first one. And then to repeat it, I'll do a box shadow.

I actually heard a neat trick. We'll say color is going to be this E color. And if you do that, you don't have to specify color on the box shadow. Box shadow. And we're going to do a box shadow. This is going to be in the x dimension. It's going to be negative 70 pix. It's going to be uh downwards 100 pix. It is going to have a whatever of of zero. And then I believe that's it. Okay. So, let's see this diff. Okay.

So, that's kind of there. Where's my border? Wimp solid red. Okay. So, this thing needs to be a height 100%. Okay. box sizing border box. That didn't help. All right, screw this. I'm going I'm going pixel pixel pushing. This is such a bad idea.

No. Oh my gosh. And I learned this trick in the YouTube comments. If I just set the color of everything to be this yellow, then that is what will be used for the box shadow. So if I set the color there, now we have a box shadow.

But it's not enough. Yeah. So 100 maybe offset. Can I do it without the px? I can't. So we need the px. Yes, we have that rectangle exactly in the spot that it needs to be. And now we can repeat it one more time. Okay. I cannot take too much time to celebrate. That has been my downfall is that I have been uh I've been doing too much celebrating. Um I'm going to copy and paste this stuff. And this one is going to be positioned and it's going to be fixed. Okay. To get it out of the document flow, I'm going to get rid of this box shadow on it right now. And I'm going to turn it to be red so I can keep track of it. And the height is obviously less. And I'm going to position it.

We're going to do left 100 pix. We're going to say top of 30 pics. Oh, it's looking pretty good. Show me the diff. Okay. Uh, pretty close. Okay. The width 49 45. Okay. Good. Good. Good. Okay. Just looking good. I think at this point we just need a rectangle. Sorry, a square that we'll then use the box shadow for to repeat it everywhere else. Now, let's get a larger square that we then repeat.

So, I'll add another P tag. Give it a Y attribute. Um, I'm going to style P and Y to all have the same stylings, but we'll reposition uh Y. We want the left to be 110.

Perfect. We want the width now to be 60. Even more perfect. I'm not playing, y'all. I'm not playing. Now I'm going to do the same box shadow trick where I'm going to say we're going to go positive 100 pix zero and then zero. Where did I where'd that thing go? This is why I wanted to get rid of margin cuz you can see when I do top zero it's right there.

So let's actually we'll have to do a negative margin -10. Let's see. It's not quite it five closer. The left needs to be increased. Feeling good. All right. Now we need those cutouts or are they cutouts or cutins? The first and last I'm going to add. So I'm going to give myself an a after display block.

Content is nothing. Height is 110%. Background is red. Width is 50px. Oh, is is can I leave off the PX? Is that was that the move? Yes. Look at all this. I'm saving. I've learned something from these. Okay, if I actually I don't need the spread on this. That is a good lesson to learn. I think I'm going to have time to optimize this. Hopefully, we got 3 minutes left. 60K top 5 px. Okay, so I think that's the right spot, but it's too wide, so it needs to be smaller. So, let me try 60. Yeah, 60 looks like that's the right amount.

Watch this move. Background inherit. What is that? Any shorter than using the hex code? I'm not sure, but it's a cool move. So, I'm going to keep it in there. All right. Now, let's put the diff on here. Okay. We need this thing to be a little bit wider. And then it needs to be moved over to the left a little bit.

So, let's just try like 165 64 65 66 67 100 pics. We're going to say 25 pics. We're going to say we're going to type in numbers till it works, folks. And then now I can just use the same one because it is 100 and I can say 200 pics. I know that it's 125 pics. And then this last one is going to be very simple where it's just zero pics and then 200. Okay, that's not looking very good at all.

No. So that one's in the right spot. We can remove this background black. We only have 3 minutes left. Yeah. So, I think for the top on this one, we'll do -4 and then give it a height of 80. Let's make these a little bit higher. Oh, that was good. I nailed that. Hell yeah.

Watch this. 56 612. Give me Give me something much higher. Oh, that was only went up two. That wasn't good. And then let's submit this. I'm going to get 100% and then I'm going to have two minutes to optimize. So, let's do it. Let's do it. Let's do it. 100% match, baby. Okay, so the top one is exactly right. We have two minutes left. Basically, I just need to copy this one um to all the other spots. So, we'll add a box shadow. Yeah. Why is it repeated three times? What What did I do here? Oh, because it's a box shadow of the entire thing. So, I can't use box shadow on the overall element, man. I I can get rid of the pics here. Can I get rid of pics here? I can get rid of pics here. Oh, man. I only got a minute left.

Okay, so do I try? Why is this not not working work? Damn it. I need to style Y all its own. Let's get rid of some of this white space and the commas. I can get rid of these zeros. I think this is what I have to do. Yeah, because otherwise it was repeated on the other.

Okay, I only have a minute left. I just need to repeat this a few times. So, we'll have a box shadow minus 165 in the X, 100 in the Y. Okay, so that was way too much. Why is that margin left not applying? Need my dev tools. Oh, it's it's the after. I have to add the after.

Ah, there we go. Okay. Okay. Oh, come on, Scott. What are you doing? You're fumbling with the keyboard. I'm like honestly so nervous. I'm like shaking. 55. That's exactly it. Okay. I only have 28 seconds left. I can I should be able to repeat this once more. Oh no. S before. Oh [ __ ] that was not good. I need to just duplicate this element really quickly. Um, so we'll have another one that has a maybe a positive 55x with 100 pixels Y. Yes. Okay. 20 seconds left.

Can I get the last one? S before 100 pixels in the Y and then uh zero pixels in the in the X. So 200 pixels in the Y. Yes, that's it. 5 seconds left. Uh-oh. Uh-oh. All right, we're taking this one off. Uh uh. Scott's waving at me. I'm pretending to not see him. All right, guys. How did you do? Wes was well beyond the He was He was still pressed and submit. He had He had an extra 10 seconds there, but uh we'll give it to him. We'll give it to him first. Thank you. Yes, I needed it. I got to uh try out some new optimization techniques, but I did not have enough time. How did How did you guys do? It was harder than I thought. I start I always panic and then start pushing pixels around, which is always the the wrong idea. Yeah, I'm worried that my fat fingering will cost me my my score here. But CJ, what do you I am just I'm mad because right now, let me let me let me I'll show I'll share mine first cuz I definitely didn't win. But I just want to show you. So right now, if I check

diff, it's completely black, right? It looks perfect. Yeah, but it's only a 90.7% match. It's because I'm zoom. It's because I'm zoomed in. So if I zoom in one, you can actually see that there like I I I I coded the whole time at this percentage, but there's like certain zoom levels where I couldn't I did I wasn't able to see the fact that what that it wasn't a perfect match. Oh, interesting.

I did only do it only 255 characters, so if I would have seen that, I probably would have gotten it, but uh I only got a 90% 90.7% match. Oh, you did good. Yeah. Wow. How did Yeah. How did you manage to do this? You did two. Okay. Yeah. So, it's two two elements. Uh you have the rectangle which is the same for each of them and then the square which is the same square just repositioned.

But what I learned in the YouTube comments is if you set color that will be used for your box shadow. So I set the color once and then I didn't have to specify the color on any of my box shadows. Oh, that's a good move. Yeah. But basically two elements and then just repeat them a bunch with box shadows. Nice. Yeah. Uh, I took a very similar approach to CJ. I did manage to get 100% match 619 317 on the characters, but I would have had a lot less cuz I I just ran out of time optimizing. Like I have a fully blank line here. Like this could have all been moved. But I did the same trick as CJ where I set the color on the initial body and then use that for my box shadows. I did end up doing like one, two, three, four, whatever. I ended up doing like six B. I could have done it with less box shadows after seeing yours, CJ. So, we we would have had like very similar ones. But I I think you given the time for optimization, if yours would have been bang on, you

probably still would have beaten me cuz I did more box shadows. But yeah, I think we had very similar approaches. So, nice work. That's that's really good. You're the winner. You beat me. Hold on, let me share mine. I was, guys, I I want to say I I was so concerned about trying to be fast enough in winning this that I was literally shaking. I was like, Scott, you barely said a word during that entire thing. I'm losing them all cuz I've been talking too much. Yeah, I switched to paragraph tags instead of divs except for that first one. You can put a paragraph, you shouldn't put a paragraph inside of a paragraph, but that will still render, right? Why did you need the div? Uh, oh yeah, you're because I was using grid to align them, but then I tried to put them in the body and grid the body and then that wasn't working and I just there's no time debug so I was just like screw it, you know?

Yes, the 10 minutes is tough. I it you think 10 minutes like to put a couple blocks on the screen is a lot of time, but it's not. Yeah, I just popped the three different ones, different attribute selectors and and applying the before. The one thing I missed is this last little one. I was trying to duplicate the positioning of this box to the right. I didn't didn't have enough time.

Wes, you got to get on the box shadow gang. I know. Should have should have. You see a repeating shape. It's box shadow time, baby. Oh, man. Yeah. No, that's not bad. You got second place. Here's something that I learned that I didn't know before this is that in a box shadow, if you don't specify the third value, there is no fuzzies. I didn't know that you could omit that. I was putting zeros for all of them and then I didn't know that either. So you could just do the XY and have it be Yeah, you don't have to have a blur. You don't have to specify zero for blur, which I thought you did. That's good. My ignorance one out there cuz I didn't know that there was a third value, so I just never put it. Third, you know that box shadow has a like a a blur value. Have you only used box shadow for like CSS shadow? Yes, exactly.

Yes. All right, CJ finally lost due to technicality, but he lost, which we're happy about. We'll take it. Yeah. Let us know if you want to see more of these. Leave a comment below and we'll catch you in the next one. Peace. later.

Quote it with credit and a link. Quoting Syntax