Syntax Video
It Shouldn’t Be This Hard… But It Was (CSS Battle)
Transcript
Welcome to this CSS battle where we are going to try and recreate this image with CSS only, as fast as possible, and in the fewest number of characters. So, we're using the CSS Battle website. And uh here, this takes into account how many characters you've typed in and how close you are to the source image.
Uh guys, are we ready to go on this purple triangle? Let's do it. I am. Today, we're going with a 15inut time limit. So, if you want to follow along at home, set your timer and let's get to coding. All right. 3 2 1. I think I can do this with no CSS tags and inline styles only. Um, BG color.
I'm doing this so I don't have to do any sort of actual CSS here. First off, I don't know how to make a triangle in CSS, so I'm going have to look that up. But we can just make the background purple as it should be. Let's do that. Awesome. We're like 90% of the way there. Now, I'm going to just look up how to do a triangle with CSS.
Okay. So my idea here is that I'm going to make a square with these patterns on it and then I'm going to rotate it and use some sort of mask. I think that is my move. So let's first take the body is a background that. Okay. And now this div here is going to be a repeating linear gradient. And I'm also thinking that yeah, we just do a triangle and then I have a a single rotated div that I just repeat with a box shadow. That's the plan. This is kind of like an arrow down triangle. I found the CSS tricks article that gives us an arrow down. So, let's give it a try. Just going to target a single element. It'll be a P. Let's just get this positioned with the exact in the exact location with the exact width and height. So people always get mad at me for doing fixed positioning. Can I make
the body a flex box and put this in the center so I don't have to fix position it? Let's do that. Okay. So let's say this is display flex justify content center and align items centered. This is why I don't use flexbox. It's so many extra characters than just fixed positioning, right? So instead of all of this, I could literally just do a top and a left. So yeah, that's why I don't do flexbox.
Regardless of if you're mad at me for not doing it, I'm not going to do a flexbox. We're going to fix position this. This is going to be our triangle. In fact, let's give it a background uh background color right now. Background. We're going to have it be background like that. The height we can also say is going to be 200 pics for now. And I'm just writing 200 to save some space here out of the gate. I'm going to do something with um clip path here and it's going to be a polygon. Okay, sorry.
This syntax to me is still very kind of rough. Um so it's a triangle. We start at a 0 0 point. Uh then we move to where we move to 100%. We move to 100%. And then we comma move to 0 100%. Okay. So this is creates a triangle. So, the way this happens, folks, is we do the the zero. I'm pointing at the screen like you can see that um 0 0 is at the top left. Then 100 100 is the bottom, right? No. Yes. Bottom right. And then 0 100 and then it completes itself. That makes it a triangle. Red 10px, black 10px, 11px. Oh, I see. Oh, this is going to be background image.
And background size 10px auto. How do you do? All right, I'm looking it up. CSS stripes 45°. What the heck is that? Oh boy. What have I done? Already in trouble. Oh no. Oh, it's cuz I'm at 45° 0°.
Okay, good. Okay, so the color we want here is this one. And then this will simply be transparent. Chat always tells me this is the fastest way to do transparent. Okay. Okay. Okay. Okay. We're good. We're good. We are in good shape. How do we make it into a nicer looking triangle? Well, first let's rotate it. Maybe rotate. Uh rotate.
We're going to Is this 90 de? I should know that off just by looking at it. No, that obviously. Let's do um is it 145? Oh man, this is embarrassing cuz it's what? It's in between 90 + 45 is uh 135. 135. Okay, there we go. And then you'd want to just put it where it needs to go.
Yeah, 85 looks good. And then 34 from the top looks almost perfect. Okay, so got a triangle mostly positioned where it needs to be. Um, now how do I change the size of this thing? So border left. If I set that to 50. Oh, okay. Let's go like 100 there. And do I need px? Yeah, I need px. Right. If I set that to 100 as well. Okay, that's going to be the top edge. So the top edge, let's get that exact to the exact amount.
So probably 140 139 38 37 36 35 roughly it. Let's go left 84. Yeah, that seems spoton. Okay, so we've got it there. And then now border top. How do I adjust this? What is this going to do? Okay, that makes it 100.
Oh, I did 190. Fascinating. Uh, so probably 200. Now, we need to make this box the right width and height and then rotate it. Oh, maybe I should just put the degrees here. 30° 50°. How many degrees is that? 55.
That seems right. Okay. No, I I think it's going to be easier to chop it if I rotate it. Okay. So, let's go to this div now and let's measure the div. So, it is 2 55x 220. The size of these lines need to be bigger. 20px.
This will be 40 30. That looks good. Okay. line content center. Okay, this div is margin zero auto. Okay, the width is too big. Maybe 220 230. That seems to be 225. That's the right width. Okay, now the height. 200.
Yes, the height. Okay, so we got the right width and height. 180 plus 45 is 225. Not not 225. I'm just gonna This is so This is so obnoxious that I am failing at that kind of math. If it's here at first, we wrote the Scott, come on. 90 + 45 is 35 + 45 again is 180 plus 45 again is the two whatever. So 180 + 45 plus 45 270 uh like 45° rotates it this much. And then you do 45 more is 90°. Then you do 45 more. Uh 90 + 45 it's 135. 135.
Oh, Scott, you're going to be so mad at yourself. We need to adjust this site here. So it's got to be like 110. Wow. We're we're we're so close. 115. Uh that's almost exact. But if we go a top of like 33 34 and then a left of 85. Yeah, look at that. Okay. Order right.
That's this one. So we got to get that in a little bit. 125 24 23 22 120 119 118 17 15. Okay, we have an exact triangle in the spot. Let's make it this color and submit. We should have like a really high score. Probably like at least 90%.
94%. Now it's just a matter of adding those those lines. If we look at the diff. Yeah, it's literally just adding adding the lines. Okay, let's do the background. And let's have it be a linear gradient. And the linear gradient is going to be from top comma let's just do FF z FFF comma 100%. I I'm not going to have to look up the linear gradient syntax again. Linear gradient CSS. I can't believe how much time I've wasted on absolutely the dumbest things in the poss in the possible world in the in the world. So you do color first and then the the position of it. I believe I need to add a stop here. And the stops are going to be yes color first. So we'll say from zero and then we'll say to 10 pics. Right.
I'm going to mask it now. CSS mask. This is what I want. It's this but the opposite. So boom boom boom here. Oh, look at that. Holy shoot. I got it.
Oh, man. I feel a lot better. Oh, I put that clip path in there. Now I'm Now I'm laughing. Okay, so now can we just change this - 455°? Is this an isosles? What kind of What's the angle here? 55 -60 66 -60 is the move here. But I have to switch the start. I'm curious if we if it'll still work with width and height.
Yeah. So, width and height. I can turn that off. And instead of transparent, I think I can do four zeros. That's less characters. And I could turn solid color into a variable. So, if I did something like var C like this, that's 1 2 3 4 5 6 7 8 characters. This is 1 2 3 4 5 6 7 8 9 10 11 12 13 characters. I feel like it's less. Let's Let's just see where we're at. So, okay. So, we're at 154 characters. We want to be less than 154.
Oh, I could do this whole thing in a variable. So, we want to beat 154. That's 158. So, it's less characters to just type it in on both of them than using a variable, even for that long thing. That's crazy. There's a repeating linear gradient function, folks. Did you know about this repeating linear gradient and we're going to start at the background color which is or no? We're going to start at this color. Uh we're going to go right to 10 pixels and then we're going to have it or zero and then we're going to go this one again to 10 pixels and then we're going to go from this one. And I know there's ways to make this shorter folks so um bear with me here. Okay, dude. I have to get this rotation finished. What the actual hell am I doing? So, we'll say 0 degrees and then we'll do - 455°. Okay, you've got to be kidding me. It was that easy. This is
going to drive me nuts. 1 2 3 4 5 6 7 8. Okay, there's eight stripes. What do I have? 1 2 3 4 5 6 7 8. I've got eight stripes already. I'm pretty close here already. Oh, I think I I think I just need to make it bigger.
Let's do that. I need the diff now. This is okay. So, 18 19 25 px. This is probably the most boring thing ever. Oh no, my angle is slightly off. 61 65. Why is it not updating?
Uh-oh. I'm in trouble. Um, let me undo this rotation for a bit. We need to get the triangle in the right shape. Oh man, this sucks. Six minutes. Okay, let's go back. Go back. Go back. Go back. Go back. I got to get something on paper. I got to get something on here. Okay, this is fine right now. We need to get the width and height situation correct. The width um 200 seemed fine, but maybe like 180. Oh, and that just goofs up. How does that goof up the Oh no. Uh let's just get the lines on there and then we'll shorten it a bit more. So I think the way we'll do the lines is by creating another element and this we will style let's just get it on the screen. Um so let's do like width 50, height 50, and a background. I guess the background color should be right, but for now we'll just make it red so we can see it. I guess I is not a block element. So we'll just do another P tag
with an X attribute. Uh and we'll do a Y attribute on that one. And then instead of targeting P, we'll target Y. It's probably a few extra characters, but I'm not going to worry about it. Okay, so we've got that there. Let's get it positioned as the last last one. And then we'll use a box shadow to repeat it. A width of uh probably like 15 and a height of 115.
200 should be good. And then I think you can just do rotate 25°. Cool. left of 200. And I'm gonna make everything position fixed. Only got five minutes left. Just gonna be down to the wire, but I think we'll get it. Okay. So, if I change the width and the height, why is that goofing up the shape of the triangle so much? Because in reality, what I want to be messing with here is the height. Now, I want to mess with the width, but I don't need it to be proportional. Guys, I'm going to have to go to a polygon creation tool. CSS polygon clip path maker. Guys, I' I'm resorting to going to a clip path maker.
This should have been what I did in the first place because I bet one of the other guys did it. Boom. Boom. Boom. I should have known better. No, no, no. I don't know what I'm looking at here. I reallyed it up now. Bring it back to where it was 15. This needs to be 40. No, 30. I think I'm just going to spend this the rest of this.
Wait, is that it? No. 4 minutes left. Just got to repeat this thing, I think, at this point. And it's not quite large enough. Is it 12 13 14? Maybe 12 and left of 229. Where is it at? Getting this in the right spot is going to be the hardest part.
Oh. Oh, what is going on, dude? I could not tell you just how much I am panicking right now. There are so many dumber ways to do this, and I chose this way. M okay. So it starts and we need to rotate rotate the linear gradient. We need to rotate the linear gradient. So it's not from two top. It's at 45 de.
Okay. It's at 40 de. It is at 50 d. It's going to be a serious Christmas miracle if I pull this off here. They're going to make a Hallmark movie about this. The gradient itself. I zoom in here. That's 22 wide. And then this is 15. Okay. So these are 22 pixels and this one will be 15. 22 + 15 37.
Okay. I think I got it. I think I am I understanding this right? 27 26 25. Am I going the wrong direction? No, I'm not. I am. So 230 31. Okay. Yeah. 231 with a width of 13 of 12. A width of 11 is it? There's a little bit of outline, but I think that's going to have to do it. Okay, so now we just repeat this thing. So, this has a box shadow.
Uh, the X is going to be 10 pixels. The Y is 0 pixels. We have to use the same background color. Oh, that's going to kill us in characters. Oh, I forgot. There's a trick. We can say the color is this and then it will use that. Yes.
Okay. Oh no, I only have 3 minutes left. Oh no. Oh no. Take this background image out. Let's just see. Do we have this right? Is this right? Yes. Okay. Okay. My gradient is not the right angle. 61 is the right amount. Okay. 35 36 37. Is that it? No. What the hell is going on here? This is a lot harder than I thought. I almost petitioned to make us have less time for this because I thought I would be better at this. And now, of course, I'm struggling with the gosh darn uh rotation again for no reason. Okay. Okay. I feel like I'm getting close. Not Not there. By no means there. Oh, okay. Mine needs to be wider. It needs to be wider. I'm an outsider. Show me the diff. Show me the diff. Okay. So, this needs to be bigger.
This needs to be um 20 pixels and 20 pixels. It needs to be 40, 40, 50. No. Okay. Not 20 pixels. Um um um um um um um um um um umumumumumumumumumumumumumumumumumumumumum um um um um 15 needs to be 15. Give me these values. Yes. Okay. 15. Then what's the next one? The next one is uh 25. Oh wow. We're down to the wire. Only 2 minutes left. We're going to have to just do this manually. Okay. Did I get that right? Okay. Okay, 53 is probably 54. 55 52. 52 is it? And do we need px on here? We do. Okay, only a minute and 40 seconds left. Do we just double it?
So, this is going to be 110 or 51 52 * 2 is 104. Okay, but there's one that needs to go before that. I guess we're just adding 26. So, 52 + 26 is 78. I think my problem is that it's where the anchoring is. Oh. Oh, it's pretty close.
What am I doing? Am I trying to scale the background up now? This is not a good idea. Um, let's do repeating linear gradient. And let's get rid of these. It gets off somewhere. Um, I'm just going to hit submit right now even though I'm not there. It gets off somewhere. Where does it get off? It gets off around the third one. So 15 25.
Why? Only 54 seconds left. And then we need one more. So 130 + 26 is 56. Okay, I think that's it. And get rid of that last semicolon. Hope for 100%. Not 99.99 because there's only 30 seconds left.
Oh, 99.9. Dang it. Ah, where is it off? I only have 20 seconds left. Let's Let's see where we're at. Oh my gosh.
Yeah, there we go. I did awful. I did awful. That was so hard. I I was using a repeating linear gradient, but I could not figure out how to anchor it. Mhm. To start on the top leftand corner. Usually on a a gradient used to right, but then I also needed a You tell me. Is it a was it 61° tilt?
I have a 30° tilt. Oh, but but that's just the lines themselves. I drew the lines and the triangle separately and the and the line is a 30° tilt. So, I did I did mine as a triangle and then I used a clip path um to clip it, right? But I couldn't figure out what size everything was and how to start it at a certain certain one. So, I wasted my whole time just like bumping numbers up and down and I I couldn't get it.
But that's a fantastic solution though. I love the linear gradient and the clip path. like, yeah, that's Well, I'll show you cuz mine is similar. I'll show you where I got and um and then we'll see if CJ's score knocked mine out. I also chose to do repeating linear gradient, but I also did very similar things. So, I did a paragraph tag width of 230, height of 200, uh I rotated at 180°, I used clip path polygon, and I did a repeating linear gradient. And I would say uh about 60 seconds before this ended, I had absolutely nothing. I I was just like I was floundering the entire time.
The edit is going to be crazy cuz I think I did I said something about if I pull this off it will be a miracle. And I don't know how I ended up here. I'll tell you that. So I got a high score of a 5 85 99.3% match. And I I just couldn't get the diff is ever so slightly off here. I couldn't get it. Dang.
Oh, it just seems like a couple pixels though. It is. It's a couple pixels. That is exactly right. That's good. Dang. Dang. That's CJ with the just hit me with the Dang. That's crazy. Like as he's about to give us like shadows. Yeah, exactly. It's not a nice I love your guys. I wish you guys would have won. It's such a better solution. Mine is just clunky.
So, yeah, I literally just drew a triangle uh with border left and border right and border top. And so I got that triangle like exactly aligned and then I have a single div that I repeated with a box shadow. Mhm. And but I mean I did some fancy stuff with the box shadow like by setting color up here then I didn't have to put the color inside of the box shadow. So that made it pretty short.
Oh, interesting. Yeah, there's a lot of neat little tricks for that for sure. Yeah, but I'm also using fixed position. I started trying to use flexbox cuz people always get mad at me for doing fixed position. Fixed position always screws you with the last 1.1%. Yeah. Uh that was obnoxious and frustrating.
Uh and nobody actually got 100%. What do you have to say for yourselves? I'm disappointed in myself and after this call I will be finishing it on my own time just to prove it to myself that I I can make a stripe in CSS.
Quote it with credit and a link. Quoting Syntax