Syntax Video
CSS Battles 3! Recreate an Image with CSS
Transcript
all right we got another CSS battle for you today we are given some random image and we have to try to replicate it as close as possible with CSS and today we have a 15minute time limit we can submit as many times as we want but whoever has the shortest solution at the end of 15 minutes wins and a hint if you guys missed it last time it shows you your character count at the very top you see how it says 540 characters right now oh man you want that number to be as small as possible oh yeah it's small as possible okay yeah cool ready ready go all right how am I going to approach this I'm thinking we could have just a div with a border like this and then use uh box Shadow to repeat it like similar on each sides yeah it could be repeated in all directions yeah so I think Each corner is a div with the repeating box Shadow so let's just get this top left corner working um so I'm going to start by just trying to do multiple box Shadows let's let's do box Shadow so we'll give ourselves a div I'm going to
do a bunch of paragraph tags because oh man I missed my tooling I got four paragraph tags we got four things here okay I have some shared styles on this and in this paragraph we're going to say what it's a square or a rectangle so I'll say width is 70 picks we'll do 70 picks for now even though I know that's not accurate I'm going to do my boxes are blue and the background is red so the background is actually going to be this red color and then each of my divs I create with border are going to be this blue color the width is going to be 50% the height 50% the background is going to be this background the next thing we're going to do is we're going to do several box Shadows box Shadow oh my God I can't spell okay box Shadow these things are going to be how wide let's see if I can do some CJ measuring so 90
to okay so 10 so so the Box Shadow is going to be 0 0 and then zero for the blur and then 10 pixels it looks like 10 isn't enough so let's say the border is 20 pixels solid that blue color and there is no background yeah like that um and so I want to get this box lined up with the middle here actually I'll get it lined up yeah I'll get it lined up with the middle to get the correct size and then we'll shift it and create border boxes for it so let's do 10 PX 10px 0 red if we do that again but do green I turn this diff off see where we're at we got a 70x 70 square so top of- 50 picks and then left of 50 picks so that at least gets us a little bit closer oh man
I've already used up so much time doing absolutely nothing and then yeah increase the size to match the center so let's go go for 200 width 180 173 172 is it just 170 yeah I think that's the way to go so 170 and then the width is a little bit bigger the colors are going to alternate between this blue color oh man I'm starting to regret this approach but I'm I'm into it three four five six let's do six um what's the Gap shoot I don't know oh I got to do blue ones in here and then I got to worry about like their stacking order I hate on this when you take the wrong approach from the start and then you're like I guess I'm committed to this wrong approach Okay so we've got one of them now I want to give this uh box Shadow actually does box Shadow even include
borders here oh I don't think it does I just need a bunch of borders okay we're going to we only have 9 minutes left at this point I think I just have to hardcode a bunch of rectangles that all like exactly positioned so this would be 30 45 60 PX 75 90 okay and then we take this blue color and do it in every other you know what if I had any sort of math chops whatsoever right now because my my brain is just not working I could just goof with this by setting the width right I could just set the width that's actually pretty pretty dang good it's looking not not good what if we transform scale oh this is yes and translate X let's do X and Y in the same okay okay uh we'll also have one that's
on the right so yeah this is right bottom right but then right and bottom right need to be absolutely positioned yeah position we'll do fix uh right zero top zero and then the body needs to have position does I don't think it needs position relative oh I need a semic in there yeah uh but then we need to flip it so I think I could to add a transform here so if I make each 400 pixels wide and so if I make the height just explicit 150 PX I'm looking at the wrong one here I got to look at the last one to size it 100 PX X is that let's see the overlay of the diff oh that's almost there W things are turning around let's go okay so with inset I could rewrite this as inset 87 that's such a dumb value there's no reason
top right bottom left trouble or No Yes trouble that's what Wes told me Wes told me trouble I'm going to use it against him we're going to delete that that didn't work why didn't that work I guess I could combine this with a rotate 90Β° 180 yes that's it Okay so we've flipped it to the other side oh man I'm just going to be getting I bet they're doing something so much better in terms of like repeating 2 three four five six all right I'm going to simply just start fussing with the scale and the translate I'm just going to start mashing it now 60 80 85 okay maybe 85 is my number all right let's see my diff okay okay okay I'm back in the game you know it's funny a lot of people don't think about translate as being an option to just do
translate instead of transform um so the translate values here we can say 25 or something this is so stupid cuz again I'm just like guessing the values I feel like that's a wrong way to do it is to just guess the values but hey just start mashing it now I'm setting myself up for failure here I got six minutes do T we'll give it a class of T we'll say right zero left Auto okay rotate 90Β° okay okay now it's kind of funky that's okay we'll we'll fix that in a second yeah this is not looking good for me cuz I'm literally only going to have the center of the image um so let's make this uh White just so I I can see it oh the missing border on the bottom one is covering up the other but that's okay cuz I kind of just want to flip it so negative 1 in The X negative 1 in the Y yes okay that's it
so only 3 and a half minutes left but I only have the center of the image okay now everything just needs to be the uh blue color and then style we'll do some inline styles for these and we'll say we're going to translate this one now this is stupid because I'm going to have to do this a whole another time in a different side sorry maybe I should focus on one thing at a time that is like kind of not my specialty YOLO just type in stuff until it works that is the motto here 340 oh that was a good guess that was a real good guess ooh that was a good guess this is not going to be the shortest by far 270 okay there we go and then Y is going to be right zero left Auto bottom zero Top
Auto and then we're going to rotate it 180Β° okay the way that this works right so now I have the two values this should be easy I have the -28 so this one can be - 28 picks so it's going to be like a positive two something a positive three something just just start typing until it works there there there are so many better approaches to this folks if you're watching me and you're like what is he doing um I concur um I'm just going to create a variable for this so we'll say B is uh that and then everywhere I need it we'll use varb this is there's no way I'm going to win this one I I'm not at all confident let's just see what our M our match percentage is not going to be very very high probably like 80% um oh 60 yeah this is not good Beauty so now I have the values so now that means
276 picks and then this one ooh I got something I got to I'm running out of time I got to save this I'm going to bring it back to where we have Okay so let's just start pushing them around 65 67 68 70 71 okay okay so position absolute we got a translate in here translate I do feel like I feel like inset could be shorter possibly and I don't necessarily know right now if I have the time or opportunity to change it I guess starting off I thought box Shadows would repeat the borders but I don't think they do and so that kind of threw me off I'm freezing we only have 2 minutes left okay let me just try to get the top left corner and then maybe that'll get my score up just a little bit uh so let's create a class for top left yeah this code is a mess oh man one minute left oh no that's not looking good at all I'm not confident that I'll be able to beat CJ because I'm not feeling good about
this one the darn Guy cheats and he has he's got a lot of like Shifty sty he he understands how to win these games probably just need to delete this code oh how many characters is that 1 2 3 4 5 6 7 8 verse 1 2 3 4 5 yeah uh dumb ah it's pretty close honestly this probably wouldn't have been the way to go it's start top left and then just gradually repeat it and increase the width and the height three 7 4 75 76 what are micro optimizations can I make in 20 some seconds am I doing wrong why can't I see it these values can't be shortened really that's not bad all right I'm going to I'm going to leave it at that how'd you guys do 62.9 percent match or score uh 157 not very good no so I had a a 62% match with like over 500 characters I only got a 154 oh I beat you yeah guys I got a 100%
match 613 points and I did it in three 359 characters heck yeah what did we do the same one we told you number 168 yeah 168 oh yeah baby I fumbled I was like I want to do this with box shadows and I couldn't figure out to do with box Shadow so I just recreated the X in the middle and didn't get anything else done oh yeah I was trying to do with gradients and then I I used I used box Shadow so I did box Shadow right same thing you guys did I did position absolute and translate and just a and you have a height on it and then I threw inline translates on the other P tags can you walk me through how the Box Shadow works here cuz I was thinking like if I gave a div a color and then gave it a box Shadow or gave it a border and then gave it a box Shadow the Box Shadow doesn't have the borders but you're not even using borders like you're just using so here's how it goes uh because you can't do like an empty
space or you could do transparent and then have a body on here but it ended up being less coated to do it this way so what you do is you do one box Shadow this box Shadow has no offset no blur and is 20 pixels wide and is orange then I have a 40 pixel wide box shadow that is blue and then a 60 pixel box shadow that is orange and they all just stack on top of each other yeah I was thinking just have an orange box or just have a blue box but you're literally alternating your box Shadow color yeah that's great my box Shadows were offset like how did you not get them to like when you offset a box Shadow it it goes down so I had to scale mine up and then I was in a mess of like translate scale and I was pushing the numbers around you don't do offset that's why I started doing offset and I realized it was the wrong thing so there's no offset on mine all all I'm doing is is there's no offset I'm just changing the width and they're sitting on top of they're
layering on top man man that's the move man that's impressive it good job I might have to quit after today give me more of these give me this one again I can do it man it was good great work Scott that was awesome so that was another let me just say incredible game of CSS battles I think that's the best one yet if you like this let us know we'll be doing more CSS battles we'll be doing uh Clash of code all kinds of fun stuff so if you like this and had a good time go check out the other CSS battles we did and let me tell you they're not as good as I'm just kidding they're great they're they're awesome even though uh the outcomes may vary so check it out
Quote it with credit and a link. Quoting Syntax