02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School

Working with Padding

A few lectures ago we discovered how to control the relation between elements with padding and now we will explore this subject more. In this lesson, we will learn how to define the space between the boundaries of a box and its content. By the end of this lesson you will know the differences between CSS margin and padding and how to apply them.

Video Transcript

00:00Just a few lectures ago, we were introduced to margins.
00:04Margins and padding are so similar,
00:06that's why they're one next to each other,
00:08but they're completely different.
00:10By the end of this lecture, you will know
00:12how to differentiate between a margin and padding.
00:16So let's jump right into it.
00:17Let's learn what padding is,
00:18and then ask yourself throughout this training,
00:21what's the difference between margin and padding?
00:24Let's jump right into it.
00:26Just like we saw the differences
00:28between outlines and borders,
00:31so exists the difference between padding and margins.
00:35So let's take a look at padding.
00:37It's so similar that I'm just gonna go ahead
00:40and just copy this margin,
00:42and I'm literally gonna use it for our padding as well,
00:45because really it works in the exact same way.
00:49But instead, I'm sending in a padding.
00:52Now, once I create a padding,
00:54notice that initially there is no padding
00:56within the words themselves,
00:59but once we created that padding changes,
01:02excuse me, and I could go and inspect that element,
01:04find the padding property,
01:06and go ahead there and show it really in gusto
01:09where I could enlarge my top padding,
01:13I could enlarge my left padding,
01:15I could enlarge my bottom padding,
01:19I could enlarge and even my right padding.
01:22So I could go ahead and create whatever padding system
01:25that I wanna do, and really the difference is
01:27that the padding is internal to the element,
01:30it creates a space between the content
01:32and the wrapper itself,
01:34while margins creates the margin between the element
01:37and things that are out of that element.
01:40Okay, so that's really the difference
01:41and the only difference between the two,
01:43and I'm gonna go ahead here and just add here a comma,
01:47comment, and leave you O2 to play around
01:49with the inner properties as well,
01:51but even before we wrap up this conversation,
01:55I just wanna say one more thing is that
01:57if you override, so for example,
01:59if let's say you want all the properties
02:02to be let's say just 40,
02:03but by coincidence, you wanna have
02:05one of the properties different.
02:07Another way for you to do it,
02:09you could override a specific item,
02:11for example, I want my padding right to be 50 pixels.
02:16Now obviously this is less smart to do
02:20because this is overriding,
02:22so if we could have done in one line
02:23which we talked about already in the padding,
02:25in the margins episode,
02:27then it would be way better for us,
02:29but this is just something to know
02:30that you could override as long as you're doing it
02:32right underneath, but if you would have done it,
02:34doesn't have to be right under,
02:36but as long as it happens after,
02:37if I've done it before, then it would,
02:39my second padding would actually override it
02:41and make it all the same padding,
02:43and it's something we've already noticed,
02:45talked about, but it's important
02:46to make sure that you realize that.
02:49A lot of times when it's something does,
02:51something that you don't expect,
02:52there's a high probability, the reason is,
02:54because something overrode what you thought.
02:56The best way for you to figure out and solve
02:59if that is the case is to literally go to your Firebug
03:01or to whatever inspector you have
03:04with whatever browser you're working with,
03:05and then go ahead there and look and try to see,
03:09is there any overrides?
03:11Is there anything that's happening here
03:12that is not what you would expect it to do?
03:16And that's it, and that covers really our conversation.
03:19Notice how by default, it merged all those together,
03:22so in a real world application,
03:24I probably would just grab this and put that in there
03:25because there's no need for an override
03:27in a situation such as this.
03:29So that's it, that was padding,
03:31and now you know the difference
03:32between padding and margins as well.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!