Syntax Video
Why Is This CSS Overlap So Hard?! CSS Battle
Transcript
We got a CSS battle today for you folks. We are going to be competing to see who can get the highest score on Entangled. This is the item that we're going to be CSS coding up for you today. And the highest score means that our code needs to be the smallest possible code to make this image. And it has to be accurate as well. 15 minutes on the clock. Are you guys ready to code this thing?
Let's see some circular radial gradients or whatever the hell Wes is going to do. Let's get going. Okay. Uh I think the play here is to get that red circle in the same spot. Yeah, Scott mentioned radial gradients. I'm just going to do a border radius circle. I'm thinking immediately I go for radial gradient cuz that's my move. But like radial gradients are are very long in CSS. So I'm wondering if two elements would be easier. Like two circles not hard. Um and then that little pie shape.
I like my little stupid BG color trick thing, which I mean, come on. Uh, BG color. Set the background on this. Give it a border radius. I'm going to make the border radius of everything be 50%. We'll use a P tag instead of a div, so it's smaller. And let's set the background of the whole page to be that blue color. Now, let's make it bigger.
So, I think this is probably like 250 and 250 height. That's too big. Probably 200, probably 150, maybe 175. But then I could I could do it entirely with radial gradients. Let's do radial gradients. Screw it. I It might be too long, but I don't care. All right. So, let's do style tags. Body background is that I'm going to do variables here. And then I'm going to just make it smaller at the end. Okay. So, gradient one is going to be the yellow one. radial gradient circle. Um, man, I always forget. I'm gonna have to go to to look up what the the actual thing is, but 50% red 100%.
And then background, we'll leave that. Background dash image is going to be the gradient one. Oh, I got it. Okay, good. So, what we want here is we want it to be yellow 200 px transparent. There we go. Okay, good.
So, what we're going to do a PA. All right. Got to have the PA. And with the PA, we're just going to say a with a height of 100 pixels. I know this is more like 200. Uh, width of 200 pixels or 100 pixels. Again, this is a circle. And then we're going to give this a simple color of yellow. We're just going to say background and and I want to go fast here, folks. I'm Sonic. Um, border radius, and we'll say 50%, cuz that's going to be shorter than anything else I have to do. 200 pixels. 200 pixels.
Sure, why not? I'm sure it's closer to 180 or something stupid. Um, there's all kinds of different ways you could position this thing. You could also just translate it. I'm going to do something interesting here. I'm going to do a box shadow. This box shadow is going to be red. This box shadow is going to look like zero pix 0 pix actually negative 100 pix zero on the fuzzies and then red. I'm going to do or sorry zero on the x-axis. I'm doing a classic box shadow here folks and I, you know, I'm trying to just get this done. I am not playing today. I am going to do absolute positioning here. So, let's just say position absolute uh let's bring it down 50 pixels from the top. Uh, we'll do it from the right. 50 pixels as well. So, let's get it lined up. Ours is a little too far to the right. So, let's bring it over more. 65ish.
200 is much too large. So, let's try 100. Is that the right size? Somebody told me that there was a trick for measuring things. I can use my screenshot tool. Maybe 80, 90, 90 pics. Okay, good. So, that's the first one.
I'm so sick of losing these things. And then the next thing we want to do is you could always do like an after on this, which honestly that's not a bad idea. We can approach different things different ways. I can have a PA, we can have a PB, you know, peanut butter and jelly, all that good stuff. Now, PB is going to be, let's just say, the same thing right now. We're going to try to get this done with time to spare. That way I can spend the rest of the time making this look nice. And instead of border radius being 50 50, we're going to say 50% 0 0 position fixed position foxed. What am I?
Fantastic Mr. Fox here. That's a great movie. All right, so it looks like this is uh clearly not the right shape. Height needs to be half of that. 160. Ooh, that does not do what I want it to do. Oo, this is going to be the hardest part. Okay, let me just make this way smaller. Let's go like just a 50x 50 circle. Let's get it aligned at the exact top center and then we can work on the width and height. So if we do right 80 90 120 and then top 44 125 124 123.
So that like align it perfectly and then we can get the width and the height exactly. But then we'd have to adjust right and left. Um, so let's say if we do 100 width, 100 height, then we adjust right by 50. 123 minus 50 is 73. That's completely wrong. Um, let's do the second one. And then we'll do vargrad 2. And we'll do background position. We want to move it over top left, top right. That didn't work. Oh, we need to do background size.
Oh, that's why everything is Oh, background dash size. It was 200 px. There we go. No repeat. Okay, there we go. Got the two things. Top left 50px. There we go. Hokey. I nailed that. Okay. And then top right negative 50px. Oh man, I nailed that. Holy smokes. Okay.
Okay. So, 100 wasn't it. Let's do 150. And I'm just going to do a calc for now. So this was 123 minus the width divided by 4. Can you do a calc like that? I guess not. So 150 / 4 37.5. This is horrible. 123us 37 is 86.
85 84 83 82 81. This, my friends, is the worst CSS battle I've ever done. Okay, now I need one more for this little pie here. So, gradient three is going to be a conic gradient. Is a conic gradient a thing? Yes. Why is it not in there?
Conic gradient from 0.5 turn. Just give me a simple one here. That's a simple one. Take all this BS out. var dash grad 3 top right 50px why is my oh that's cuz I have the word background in here we go somehow I've done it so it's a 18 I don't know why that took me so long but it's a 180 x 180 circle and then just offset by 60 o okay next I'm just going to create a yellow circle right behind it and then after that we'll create a semicircle on top call call it done. Uh, so we need another P tag. Uh, we need the yellow one to be drawn first. So I'm just going to give this an attribute of Y. Going to style both of them. And then specifically for Y, uh, we'll set its right to be much much bigger and its background to
be that yellow color. Okay. And now all we have to do is get the right. So, let's try 150, 155, 160. Okay, that gets that. Now, we just need a semicircle right on top. I'm going to go ahead and submit just to see if there's anything weird cuz we should get really close here. Like at least 80% I think. 96.6. You know what? That was like um the thing that I thought was just going to be the answer. How do you do a dang half circle? I have no doubt that they're googling this right now because that's the type of guys they are.
Um how do you make a semicircle in CSS? I don't know. I am going to search the web width, height, border radius. Uh, so I'm doing something wrong. So the height should be 90, which is h Oh, the height should be 90. Um, sorry, I found an article that shows how to do it. And then the border radius needs to be what the height is. So like that. Okay. So it turns out it was easy. So, you know, theoretically here we could just position fix everything and that like we could get a something on the board here and we can say this is going to be left 100 pixels. This is going to be left of 50 pixels. Again, this is just kind of classic uh guessing. You know, like I said, we're going to lock in a score here at least. That way, I have time to goof around with other things. Let's put on the the diff here. Let's get this at least lined up a little bit here.
I want this pie, but also shoot. I'm going to have to do like border radius on something. Damn. Foiled by the conic gradient. I like uh get this box shadow over a little bit more. A little bit less. A little bit less.
Less. Uh no, not 190, bro. So, like there's clearly something up with the top here. 8 minutes left. Let's see. Is this a Is this a 100% accuracy? If this gives me 99%, I'm going to throw my computer out the window. Where does it even say? It says my high score. Accuracy. Where's the accuracy? Here's the last score. Here's the high score.
Where's the accuracy? Don't just tell me a score. 100%. Bingo. Bingo. Um, copy this. Let's mix it down and then let's optimize it. background dash image var Brad one beautiful okay you know what um we'll do and after content is nothing display block um background red width 200 px height 200 oh oh okay um border radius Yes. 100%. Okay.
Position absolute right. 50px top 50px. Why is two is 200 too much? This is where it all falls apart. Can I tell my goofy movie story? Maybe I should tell my goofy movie story while I'm doing this. Uh I was on a plane and the goofy I tried to tell the story one time and it got cut for time. So I'm going to try it again. Uh I I was on the plane.
Order top left radius. Ah, okay. That's a that that helps. I like that. Okay. Basically, you only set the top left and the top right and don't set the bottom left and the bottom right. So, I want one more element and this is going to appear on top of everything. And I'll call it C for or I'll call it S for semicircle. And then we'll target the semicircle. And we'll also apply that all the other styles to the semicircle as well. And we'll apply the color to the semicircle, which should put it right on top of the red one.
Yeah. So now it's on top. And he kind of like looks over at me like, "Haha, don't you love the Goofy Movie?" Um like, "Sure." Top left, top right, border bottom. Is there any way to do that shorter? Cuz those are really long CSS properties, I guess. Yeah, you could do it with the um border radius. Angry. And this was after an international flight. Like I was livid.
Like get me out of here. Get me off this plane. Get me away from this man. Okay, that's the right that's the right spot. Okay, now what we're going to do is we are going to instead of having the background red, we're going to have the background to be the grad 3.
Beautiful. Okay, so now we got to work on this gradient. That was the goofy movie story. I think I might have told it better the first time. So if we do border radius 100 pixel pixel zero that's getting weird. Let me make this a weird color so I know what I'm styling.
Is it does Can you do like top left right bottom? Let's try it. 0 0 0 50% 50%. Okay, that sort of does it. And then I guess we just change the height. Uh so half of 180 is 90. I didn't need a calculator for that. Okay, that completely breaks it.
So, I guess I have to change the height. All right, I only have 4 and 1/2 minutes left. This has been very hard for me. Um, um, you could also do one position. Let's just try it. Did we have determined that align item center does not work in CSS battles or what? Because like I forget. And same with inset. Like those are two that it's like did that align item center. H I feel like that's one that gets me every time. Align items center CSS. Does it need to be position relative? Does like is there something I'm missing about align items? Align items on ch all children of the group.
Align items center should put all my stuff in the center, but like it doesn't. We're going to make that green just to show us where the rest of the gradient is. Okay. So now I want to start at 180. No, 270.
There we go. How do I just make that? Oh, the green is what I want. What is this 10Β° do anything? Why? I don't understand. All right, let's just leave that at zero. Okay, so this is going to be transparent. Oh, people told me a trick.
Look at that. Okay, now we make this green this color. I think I got it. Submit 100%. 100%. Come on. 100%. Okay, now we got to make this smaller. How much time do we have?
3 minutes left. None of this is working. I see I see Wes Wes celebrating over there. H. Okay. Um, maybe I shouldn't go with the AI answer. Just show me a semicircle. Darn it. Okay. Yeah. What did they do here? 10 rim. 10 rim. 0. Oh, just half the height. Half the height.
That's what I tried. I thought 180id 2 is 90. I got that maths right. Oh, what did I do wrong earlier? Cuz this is right. Okay, it's working. Now all I have to do is just set the top. What other kind of optimizations can I can I get here? Did I remove any pixels? There's a height pixel I can remove there. I I actually, it's funny, I wrote myself a little cheat sheet here. Omit closing tags. Color. Is there any color stuff I could get rid of? We have this background color on both. Border radius 50% seems like the best way to do that.
Is there anything that I am applying the same value that could be on both? So, this top of both P's. I could have a another P top 40. And then I can get rid of this top 40. Get rid of that semicolon. Get rid of this top 40. Get rid of that semicolon. That looks a lot shorter to me, folks. This is not very short. Um, so what we'll do is replace this. Okay. Gradient two gets replaced with that. That's still less. Okay. No repeat. Do we need no repeat on there?
Yeah, we do. Damn, that's going to kill me. Let's get rid of the background color here. I see an extra space there. I only have 2 minutes left, so I'm not going to have much time to optimize beyond this. But I do need to bring it up a little bit. [Music] Let's hope I I beat these losers. All right, let's see what these losers are saying. What's up, Wes? We both finished ours off saying, "Let's see what these losers did." Uh because it's the same thing I said.
How did everybody do? Good. I finished with like 9 minutes left. So then it was like trying different things out and ultimately I don't think I could have done better unless I really changed the approach which I I you know I could have done that but like I would have need to really change my approach and I did not. So yeah. Yeah, I was I was down to the wire for some reason. I just can't think in CSS today. So but I got there. Got to 100%.
Oh CJ, you got a great score. Oh CJ beat me anyway. Yeah, CJ beat me too. He had a great score. Oh wow. Okay. Hey, I just can't speak in CSS, but still wins. I just thought this was a bad solution. So, basically, it's just three divs, right? I've got the red div. Yeah. Uh or three three P tags. Red div fixed position and then a yellow one fixed position and then the last one is a semicircle fixed position as well. I I think what I was not proud of is is all the fixed positioning. Also, I couldn't figure out like the it took me so long just to get the width and the height of this circle. Like I was just debugging like 1 160 170.
Yeah, but I got there. It's nothing crazy. All right, let me show you my solution here. All right, I got I got 608 and I did go for the radial gradient and it it killed me because the word radial gradient is just too big. But I was actually really happy with my approach. So I did two radial gradients and then this little pie cutout that has to overlap right here. I was going to do a conic gradient, but then I realized like a conic gradient goes right to the end. So, you can't do a circle, radial, and like a pie shape. What I ended up having to do was I used a second element, an after element, and I just I I positioned it, and that killed me. Uh, yeah, you took the most overly complex approach to this. I got to say, certainly had a fun time. I also lost to CJ, but I I don't necessarily And I don't want to I I don't know how necessarily cuz I was right there.
Um Oh, you 640. I only used two elements. One element is the yellow one and then I had a second red one which is just a box shadow. Um and then I used a half circle that is just another paragraph tag. Um, and I don't understand necessarily how this was less code or more code. Yeah, it is. Somehow you covered up the top with a red semicircle. I actually covered up the bottom left with a yellow semicircle.
Yeah, there's a glass half empty guy. Yeah. Yeah, guys, that was an awesome CSS battle. We actually all crushed it. CJ, I can't believe yours went to the the I finished mine with like 8 minutes to go and had all that time and I was feeling pretty dang confident with my solution. So, I'm going to be a bit of a sad panda over here, but uh good solutions, guys.
Wes, um I'm just glad you had fun. All right, congratulations, CJ. You did great. Even though you were not on top of your game today, you are the winner of the game. CJ, uh lovers, rejoice. We'll see you in the comment section.
Quote it with credit and a link. Quoting Syntax