Placeholder Image

Subtitles section Play video

  • creating box shadows manually sucks.

  • So in this video, we're gonna create a website that allows us to visually create box shadows instead of having to manually create them.

  • So let's get started now.

  • Welcome back to Webb.

  • Have simplified my name's Kyle.

  • And my job is to simplify the wood for you so you can start building your dream project sooner.

  • So that sounds interesting.

  • Make sure you subscribe to the channel for more videos just like this not to get started.

  • I have the final version of our project on the right, and you can see when I update any of these numbers.

  • This box shadow is actually updating based on all of our different values.

  • We can even modify the color, for example, of the shadow or of the box.

  • Or we can even change the background color if we see fit.

  • So we have complete customization over what our shadow looks like.

  • And now to get started, I just have a blank project open and visual studio code.

  • We're gonna need to create first and html page, then a CSS page.

  • And then lastly, we're gonna need some form of javascript.

  • So we're gonna also need a script here.

  • So let's get started with the HTML because this is going to be the easiest thing.

  • And if we just hit exclamation point, enter generates old a boilerplate for us that we can link in our style sheet, which is stiles dot CSS and we're also going to link in our script tag, which is script dot Js and we're just gonna make sure to defer this so it loads after the rest of our body content.

  • Also, let's just give this a title here.

  • We're just gonna call it to Fox Shadow Gooey just like that.

  • And now in the body, we can get working on creating the elements we're gonna need to create this You I on the right.

  • The first thing that we're obviously going to need is a square for our box, and we're just gonna give that an I D of box.

  • So now we have a div with an idea of box which is going to represent our box in the middle.

  • And in order to get this box to be centered inside of our screen, we're gonna wrap it inside of a container.

  • So we're gonna use a box container class Div, and we're gonna put the box inside of that Div.

  • This is so that we can easily center this using flex box later.

  • The next thing we're gonna need is this side war.

  • So let's create a sidebar.

  • And if you're confused, how I'm creating classes by just typing a period and then hitting enter.

  • I have an entire video on that topic, which you confined in the cards and the description down below.

  • Now to continue on with our sidebar instead of here.

  • We have a bunch of different labels and inputs, and we also have this divider line.

  • So let's get started first by adding in a label, and this label is going to be four x position and it's just going to have the label of X.

  • Then we're gonna have an input, which is going to be a number input, which is going to have a name of exposition, and it's going to have an I d.

  • Of X position.

  • Now we're gonna have to copy this down a bunch of additional times.

  • So it's just copy this label in this position and we're going to do the same thing.

  • But this is going to be for a wide position.

  • It's going to have a label here of why, and the name and the I d are both going to be y position.

  • Next, we're gonna do another input here.

  • This one is going to be for our bowler.

  • So it's just make sure you change this to be for a blur.

  • Our label is Blair hopes not Blue.

  • Where and our name and our i d are all going to be the exact same of Blur just like that.

  • What's copy this down again?

  • We're gonna do this first spread.

  • Make sure this says spread here and there we go.

  • We ever spread value done.

  • And the next thing we can work on those are actual color.

  • So we're gonna have another label here.

  • This one's gonna be for Shadow.

  • It's gonna have a label of shadow and what we're gonna do inside of this label here, we're gonna have a input which is going to be a type of color, and it causes that nice color picker that you saw on the right hand side.

  • And we click on this this fancy color picker that's by using type of color and we're gonna set this name to be shadow, color and the I d to be shadow color.

  • And we're also gonna make sure our four is also shadow color.

  • Now it's copy that down two more times because we're gonna have our box color.

  • This is just going to stay here box and make sure we replace all these shadows with box color and again appear we're gonna have background color.

  • Let's just move this down below our box.

  • It's that it's easier to work with their radio.

  • So this here is going to be our background.

  • And let's make sure we change this to background change this to background color and also this one to back on color.

  • And now if we open this up with live server over on the right hand side, he'll see it pop up in just a little bit.

  • You see, we have our X y, all of our different inputs as well as our different color pickers.

  • So everything is showing up there by default.

  • Obviously, our box is not showing up because it's just an empty def.

  • Right now, we don't actually have any with her height inside that the last thing we have left to do is add in this horizontal line.

  • We're just gonna create a div called divider.

  • And that divider, def is what's going to represent this horizontal line here which divides our top and bottom content.

  • This top section is all for the box shadow and his bottom section is extra things such as the color of her box and the color of our background.

  • And that's all of our HTML for now that we're going to need.

  • So it's actually jumped into styling this HTML.

  • The first thing that I want to get started with is just to change our box sizing on every element to be border box makes working with our width and height so much easier and then in our body, let's remove all of our margin, set that to zero and then work on how we're actually going to lay out our box and our sidebar We're gonna use Flux Box to do that, so it'll be side by side next to each other.

  • We're gonna change this to display of flexed, and we're also gonna make sure that the minimum height is going to be set to 100 view height that just ensures that our body is going to take up 100% of the height, which will make center in this box much easier later on so that we have that done.

  • You see, our margins were removed on our body, which is great.

  • The next thing that we're going to work on is actually pushing our sidebar over to the side and building out our box.

  • So we have our box container and we're gonna have our sidebar here.

  • And our box container we want to Philip is much available.

  • Place space as possible.

  • So we're gonna set this to flex grow of one.

  • And as you can see right now, nothing happens because there's no additional space horizontally.

  • So when our sidebar, what's set a minimum with here, which is just going to be 121 130 pixels.

  • Sorry.

  • And we're also going to set a actual with of 20%.

  • And the reason we're setting both of our different wits is that the smallest we ever want this to be is 130 pixels.

  • While if our screen size is very large, for example, like this, we wanted to take up a full 20% of the screen, so it doesn't look too small on the side of our screen.

  • But when it's really small, we only wanted to take up 130 pixels.

  • So now, with that out of the way, we can see that our box container is taking up all of this extra Romanian space here in order to actually visualize our box.

  • Let's select that box, which we know has an idea of the box and give it some with and heights.

  • We're gonna say maybe 100 pixels of with and tight, and we're gonna change the background color to just be read.

  • For now, it'll be really easy to see.

  • And as you can see, we have that nice Red Square in order to center it.

  • Like I said, we're gonna use display of flex, and we're gonna justify our content in the center.

  • And we're going to a liner items in the center, and that's gonna put our box of dead center instead of our screen.

  • Between our sidebar and the top and bottom of our screen.

  • I also want to give our box a little bit of a margin.

  • We'll just say a margin of 25 pixels on all sides.

  • That way, if our screen size does shrink down, it never becomes so small that our box is not able to have a border around it.

  • We want to build to show that box shadow.

  • So we wanna have a little bit space around our box, even if our screen size is really small.

  • So now the next thing we want to work on is changing over our font family, because right now the default font kind of looks ugly.

  • Soldier shoes Ariel as our front looks a little bit better.

  • And now we want to work on styling out this sidebar because our body of our box content is fine for now.

  • But we need to work on the side bar because it's pretty ugly right now.

  • So the first thing I want to do is changing over to use flex box, and this is because if we change the flex direction to column, were able to stack everything on top of each other.

  • As you can see, every single input is stacked right on top of each other, which is really, really nice.

  • Also, it prevents our inputs from becoming too wide, because without this flux direction, you can see we have really long inputs that go all the way to edge of our screen.

  • But if we make sure use flux Box, you can see that scroll bar is no longer there because our inputs actually stopped right on the edge of our screen.

  • Lastly, for this sidebar, what's adult Patty, who live 0.5 or E.

  • M.

  • Top bottom and one R E m on the left and right?

  • Give it a little bit of space and we'll also change the background color.

  • And we're just gonna make this really dark color just to to to looks pretty good and we'll change our color toe.

  • Wait so we can actually see the text inside of here.

  • And already this looks much better and pretty somewhere to what we have over here.

  • All we have left to do is actually focus on style in our inputs and our spacing, and we're pretty much there with our styling.

  • In order to space are elements out?

  • Let's select our labels from our side bar, so it's a sidebar label, so every single label that's gonna be X y and so on.

  • What we want to do is add some margin on the top.

  • Will do 0.75 r e m And we're also gonna add a little bit of margin on the bottom of 0.15 R e m That way we have our actual inputs spaced out from one another, and the label is just slightly offset from the actual input.

  • Just giving it a little bit more space.

  • Which books?

  • Good, in my opinion.

  • Also, we're gonna want to set our font wait here to be bold.

  • That way these labels really stick out that we know that they're clickable.

  • Now, the next thing to do is work on this divider, if you remember, recreated an element in our HTML with a class of a divider.

  • So we can actually just select that divider by saying divider and all we want to do is give some space around this.

  • So we're gonna use margin.

  • We're going to say we want one r e m to be on the top.

  • We want negative one r e n on the left.

  • And the reason for this is that we have this padding of one R e m and we need to offset that.

  • If we were to have zero here, I'll show you what that looks like.

  • It just a little bit.

  • But on the bottom, we're gonna have a 0.5 r e m.

  • And on the left, we're also gonna have negative one R e m.

  • But for now, I'll show you what that looks like with zero, and then we're just gonna use a border for this Will save border bottom is going to be one pixel solid.

  • And we're gonna set this color here to be 999 And if I save, you can see we get that divider.

  • But as I mentioned, it's one r e m away from the edge on both sides because of this padding.

  • So we want to do is make sure that we have here are negative one r e m of margin, which is going to push this all the way up to the edge of both of these sides.

  • And the reason we have a different margin on the top than we have on the bottom is because of the margin top and margin bottom that you see on our label.

  • We have 0.75 year and 0.15 year, which is a 0.6 difference.

  • So actually, this should be point for R E m on the bottom like that, so that when we haven't even amount of space between the top portion of our divider and the bottom portion of our divider now all of that spacing done what's work on styling our inputs.

  • And we're gonna first style our number, inputs and then style or color inputs because they're obviously gonna look quite a bit different.

  • So let's select our inputs, and we want to select the ones that are not color inputs first.

  • So we're going to say not type equal to color.

  • Just like that.

  • This is going to select every input.

  • That's not a color input, which in our case, is these four number inputs.

  • And what we want to do here is we're gonna add a little bit of padding on to these for 2.25 pm and 0.5 pm just to give our numbers some breathing room inside of here, and also you'll notice our font is different.

  • So we want to make sure that our font family is going to inherit and our font size is going to inherit.

  • And that way our inputs have the exact same fund and font size as the rest of our application, and that already is starting to look better.

  • Now, the next thing that we want to work on is going to be our border.

  • We're actually going to completely remove the border.

  • But instead of saying border none here, where we're actually going to say, is one pixel solid, transparent.

  • And the reason for that is that inner input focus states our input.

  • No, it's type equal to color of focus.

  • What we're gonna do is actually change our border color to be this oh, a f color.

  • So now when we select it, we get that o f color.

  • But if we were to set our border to none here and we select, we're not gonna get that away of color going around as we would expect, especially if we turn off our outline 10 none, which is what we're going to do.

  • You'll see that we don't get that blue color at all.

  • But when we have our borders set to one pixel solid, transparent, we actually do get that one pixel of space and our blue border is able to show up when we click on our element, which is really good.

  • Next, we're gonna set our border radius.

  • Which word is gonna use 0.3 e m.

  • Just to give it a little bit of a rounded corner.

  • And now when we click, you can see that looks really good and that's everything to styling these number inputs.

  • So let's go on to styling our input.

  • That is going to be our color input.

  • So we'll say input type, equal color clips color just like that.

  • And inside here, the first thing I want to do is just set the with to be 100% such stretches, the full with just like the rest of our inputs do.

  • And I want to use that same border radius of 1000.3 e m Just like that.

  • That looks pretty good.

  • And we're gonna change our background color here to be white just so that we have the same background color for inputs as that we do for our color inputs.

  • Lastly, I want to remove the border from this will set the border to be equal to none and I'm also going to change the cursor to point her.

  • Just so it's really obvious that you can click on these to change the color.

  • And as you can see, everything is working correctly.

  • Now we can actually move on to the Java script portion of this and how we're gonna link everything together because that's the most important part of this application.

  • And in my opinion, the easiest way for us to link all of this together is to use CSS variables.

  • So if you remember, in our HTML, we have this unnamed property and we set this name property to shadow color, box color, background color spread, So one and we're actually gonna name CSS variables after the name property of each one of these different inputs.

  • So what's gonna happen in our Java script is we're gonna set a bunch of variables on our route element, and then we're gonna be able to use those inside of, for example, our box.

  • So here we can use a background color variable to set our background color.

  • But by default, this background color variable is going to be blank, so we actually need to put a placeholder value inside of here, and we're gonna use a placeholder value here of F f D 700 This is going to give us that yellow color.

  • And let's just make sure we copy this place holder and put this place holder here into our background color property as the value.

  • So we're gonna set the value here equal to that and in juicy our default background color in our input is going to be the exact same as the background color of our actual box.

  • And this is just so are different.

  • Inputs are going to be linked up at the beginning because when our page loads, we want to make sure inputs and our display are exactly the same even before a Java script starts working.

  • And the next thing we need to do is build this set all of the different box shadow properties on our box.

  • So to use a box shadow here and we're gonna have just put this on to a new line because this is going to be a quite large explanation here.

  • The first thing we're gonna do is our exposition.

  • So we have a variable which we're gonna call exposition, and by default.

  • Let's just set that tow three and we need to convert this value of 32 pixels.

  • So what you're gonna say couch three times, one pixel on what this does is it converts this value of three here or whatever it is 123 10 200 multiplies it by one pixel, which converts that value to pixels.

  • We could do the exact same thing, but for our Y position, which will also just default to three.

  • For now, we also need to make sure that we set our blur.

  • So let's just copy this down, set our blur, and we're gonna just default this to five.

  • We'll copy this down one more time for our spread.

  • Much does default this to six, for example.

  • And now, if we save, you can see we get this nice box shadow over here, which has all of these default values set.

  • But our inputs do not have these defaults.

  • So instead of her input was, make sure we set our default values.

  • This one is going to be three are y position has the exact same default.

  • So it's copy that over our blur, if you remember, has a default value of five and are spread here, is going to have a default value of six.

  • So now our default inputs line up with our actual color here.

  • Also, we need to make sure we include our color in here.

  • So we're just gonna do our virus, which is going to be a shadow color just like that.

  • And our default value for this is just going to be 000 It's going to be black.

  • So now inside of here, let's make sure we set the default value for a shadow color to be in here to be 000000 And that's going to just make sure this default value is black.

  • Also, we're gonna want to do our default value for our background, and it looks like I actually put the value for our box color on the background input.

  • So let's make sure that's in the right spot that we go and let's do the default value here for a background which is just going to be zero or f f f f f f for a white color.

  • Now, if we jump over into our styles, the last thing we have left to do is to come into our box container and set the background color to be based on our background color variable.

  • And it's going to default to that white color of F f f.

  • And as you can see, everything is looking how we want it to.

  • And we can finally move on to the Java script so that we can change these variables.

  • And if you remember right in this index dot html, every single variable corresponds with their name, property of that input.

  • So now in her script, what's actually select all of our different inputs Weaken, Say document hoops documents dot query selector all and we want to select all of the inputs and we're gonna loop through each one toe at an event listener for whenever they change.

  • So for each one of our inputs, what we want to do is take that input and add an event listener which is going to be on the input event.

  • Essentially every single time we make any change in all, this event is going to be fired and we're just gonna call a function which is gonna be called input changed.

  • So it's create that function, lips function input changed.

  • And this is going to take in the event.

  • And what we want to do is select our document and whoops documents, and we want to get the root elements.

  • We just say document element.

  • We want access this style because this is where we can actually modify the CSS.

  • I'm gonna call a function called set Property.

  • And inside this function, we need to pass it our property name, which is going to the e dot target dot name.

  • This name, for example, is going to be shadow color like this.

  • But we need to make sure that we have two extra dashes in front of this name.

  • So to do that, we can put two dashes and then inside of there we have our target name, and then we can finish that off, and we're just using temperate liberals for this.

  • So we use this back tick symbol as well as this dollar son with the curly brackets to put a variable inside of our string.

  • This is going to convert our name to a name with two hyphens in front of it.

  • We want to set that to our e dot target that value.

  • This is just whatever value is inside of our box here and now.

  • When we save and we modify our X value, you see that moves modifier.

  • Why it moves.

  • We modify our blur.

  • You can see it gets more blurry, are spread is gonna make it more spread out.

  • Let's make sure all of these work so we'll change our shadow here.

  • Change that color door box to green.

  • And we noticed our box did not work.

  • So let's see what's wrong.

  • If we go into our index at each team, will we have our name set the box color and in our style sheet was See what we have on our box.

  • We used a background color here, so let's make sure we set this to box color and now you can see that Green Keller was properly applied.

  • Tarbox.

  • Lastly, let's change.

  • Our background will change it to this color here, and you can see our background has updated.

  • So all of our different variables are now linked up, and all we have is just these few lines of Java script because we were smartly used the name property of our input to determine which variable in our CSS we were gonna modify.

  • And that's all it takes to create this really useful visual tool.

  • If you enjoyed this video, you can check out some of my other projects, looked over here and subscribe to the channel from more videos just like this.

  • Thank you very much for watching and have a good day.

creating box shadows manually sucks.

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it