Box-sizing & Border-box
Hi everyone. This video is about box sizing and border box and it's magical. Nous Okay, we've got these boxes here. I want to add some padding to the inside to just to line all this stuff up. But when I do that padding added and the boxes got bigger. Okay, you just you add petting and it seems to make the boxes bigger. Weird. So we're gonna add box sizing and border box and magically we've got penning but they didn't get bigger. No more minus ng the petting from the size and width of the boxes. It's magic. Let's work out how to do it now in venus code. So what is this magic box sizing? Border box goodness. Okay. It relates to flex box again. Okay. It's one of its nice little add ons for html five. It's got great browser compatibility. And what it means is we can add petting without breaking our boxes. So you'll notice that we've danced around like we've put padding at the bottom of the P tag to push the bottom down. We added padding to the top of our icon. We added padding to the P. Ta...
g here on the left and the right to keep it away from the edges. Why didn't we just add it to the card itself? Just put a border around the outside. That's easy. All right, because it breaks it. Okay, so what we're gonna do is let's prove the point. Let's go to our card actually let's add a couple of classes do it 11 big go. So let's do card one comma. Card two comma and then card three. Okay so you can do them all in one big go. As long as there's a comma there you'll notice before we did a compound. Where is it this one here? This means these guys have a relationship to each other. Okay. Eight tags inside of cards. Whereas this thing we're making now is this comment and this and that. They're all like separate little things. So commas separate them out. If it was without the commas it would be looking for a card three that is inside of a card to that's inside of a card one which doesn't exist. Okay so we're going to add padding And we're gonna do it all the way around. Just do 20 pixels. Okay save it let's have a little look and it kind of blew out the edges here. Okay. Went too far so it didn't add it to the inside. Weirdly it added to the overall size. If we make it even bigger so we get it up to 50 you'll notice that just goes bananas. Okay they all start pushing into each other and ours is not breaking too badly but So the padding is there 50 pixels but it adds it to the size and that's where border box works. Okay so what we can say is actually add that padding but we're going to do box size box sizing and we're going to use border box and hit save and the good thing about it is it removes it off the wits now. Okay. And it's just a nice easy way to do it. We're going to remove the stuff of the petting, okay. And that we've done okay, also off the P tag, so we'll clean it all up because we just we kind of danced around it for a long time because I feel like you're ready now. Okay, ready for border box. Yeah, just because what you could do is you could go through here and say actually, okay, so we're going to do that and then we're gonna start minus ng off the width. So we're going to say width equals minus, and you can start trying to minus off what you add the padding to and it just does your head in. Okay, So that's what you have to do. So let's fix this. So we've got border box comeback border box, let's first of all get rid of all of the other things we did. So we did under the P tag, we did margin bottom, which we do need that. It's cards bottom. We did. So we did margin around this thing, we still need the margin just above it. Okay, so we'll do margin top, definitely. Okay, margin hyphen top, but we don't need all of the rest of this, what do we use? We used 30 left and right and 20 at the bottom. Okay. And you were like, why don't you just keep doing that way because we didn't get to learn border box. If we do it, just leave it this way and you're going to run into it in code and you're gonna run into that problem of just like, hey let's just put padding around it. Why is it adding to it? The same with that margin? It just adds it to it. But if you want to magically minus the margin or padding off the overall width of the box, use border box. So let's go and do that. Let's find I'm getting a little bit lost now you might be the same. Okay. Border box. So the petting in this case is going to be at the moment. If you just put in one attribute it goes all the way around remember? So the top in this case, what have we put over the I tag so pending top because that's what we put kind of in this topic here. So we're going to do this fella and say the top is going to be, What did I just say 30 Okay, 30 pixels Or G. Pixels. Okay, the left and right. It's going to be 30. Okay, don't use semi colons at the end of them. Okay, so Top right, bottom, I can't even remember now. 20. We'll have a look at it. Don't put that in there and the last one is 30 awesome. So that should work. Let's have a look here we go. If I saved it, I have Nice so it's kind of a backwards way to do it. Right. I just kind of kept this a little bit later on in the course. And so now probably when I first put my cards in, I'd add the padding before I dumped all this stuff into it and just make sure I use border box on those cards. You can use them in individually. So this could be in. I could cut that and put it inside all of the cards. Okay. And I have it in there three times. I've just kind of kept it separate for this video and the better. I'm not sure it's saving much type. But anyway, that makes sense. I hope it did without it. Turn it off. Let's have a look. Okay. The boxes just get its original 30% plus this padding and I could minus it off the 30% but minus thing pixels off percentages is mind blowing. Okay for me at least. So it's better just to add it to it and then turn border box on. All right, job done. High five. I will see you in the next video