Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Most of the time, if I need to control spacing in my typography, I use margins. However, there are times that padding is required to achieve the desired result. While margins control the space between elements, padding handles the spacing within the element. Each element is contained within its own box. Increasing the Padding increases the distance from the contents of an element to its edge. Keep in mind that this can also increase the total width and height of elements, and that needs to be factored in when determining the relationship of surrounding elements. In this movie, we'll use Padding to achieve nicer spacing for our Tour Resource links.
Then control the amount of inset that is frequently asked questions answers have. We'll also modify the relationship between a headline and its border. So I have the faq.htm opened up. Let's just to scroll down so we can see the elements that we are going to be affecting. So here we have a couple of links that will jump us down the page to our frequently asked questions. They're inside these list items. You can see they have a background color and a border applied to them. So to give that little bit more spacing, open them up a little bit, make them look a little bit better, we're going to use padding to help us with that.
The answer portions of our frequently asked questions really need to be sort of offset a little bit. So what we're going to do is we're going to inset those, so that they have a little bit of space over here on the right-hand side. That's going to give us a nice little visual separation between the answers and the questions themselves. Then finally, Monthly Specials has a border applied to the bottom of it, but the border and the text are almost touching. So we're going to use padding to open that up a little bit more so we get a higher degree of space between there.
So let's start with our links up top. Now what I'm going to do is just go ahead and use my Code Navigator. So remember, I can Alt+Click that on the PC, Option+Command+Click on the Mac, and there are a lot of rules here. The one that we're looking for is this one, #mainContent #mainArticle ul.faqNav li. So that's targeting any List Item inside of an unordered list with a class faqNav, inside of the mainArticle, inside of the mainContent.
Okay, I'm going to go ahead and click on that. Once again, if you want to be able to see this while you're doing this, you can just sort of move that divider so that you're seeing less code, more design, but I'm really using that to find it over in my CSS Styles dialog box. I'm going to go ahead and double-click that Rule to open that up in my CSS Rule Definition dialog box. Now remember, you want to look right up here to make sure you got the right Rule, li ul.faqNav mainArticle mainContent. Cool! So now I'm going to go to my Box Category.
You can see we're controlling Padding and Margins through our Box Properties. I'm going to deselect Same for all. I'm going to do a Top Padding of 0.5ems. I'm going to do a Right Padding of 0.5ems, a Bottom Padding of 0.5ems, and finally, a Left Padding of 1 em. There we go. So Top, Right, Bottom all of 0.5 ems, and then a Left Padding of 1 em. When I click OK, I can see I have an increased amount of spacing all the way around, and these links are now getting a lot more attention, visually, on our page.
Let's scroll down to take a look at our frequently asked questions answer portion of it. If I click inside of that, I can see that this is part of a Definition List. So I have a dl there. We're going to be targeting that dd tag. So once again, I'm just going to go ahead and Alt+Click or Option+Command+Click on that. I'm going to bring up my Code Navigator. I want to find the #mainContent mainArticle dl.faq dd. When I select that, I can go right over to my CSS Styles panel, double-click the one that's highlighted.
It's a very fast and easy way to find your targeted Rule within all those styles. I'm going to click on the Box category. Again, I'm going to deselect Same for all for Padding. I'm going to do 0 Padding for the Top, 0 Padding for the Right, and 0 Padding for the Bottom, because all we're really wanting to do is move this over a little bit to the left. Now if I wanted to, I could have left all that blank. I could have just left Top, Right and Bottom with no values and given it a Left value. For Left value, we're going to give it a Padding of 2em with no spacing. Now you can also write that this way. You can say 2, and then you can grab the pulldown menu, choose ems.
I just find that to be a little faster. When I click OK, click back into my file in Design view, and we can see now we have a little indentation for each of those guys. There is a nice separation between the answer and the question itself. Now let's take a look, finally, at our headline right here, Monthly Specials. If I Alt or Option+Command+Click that, what I'm looking for here is this callOut h1 selector. So I'm going to go ahead and select that. Again, I can just com right over to the CSS Styles panel and double-click that. It's going to open up my CSS Rule Definition dialog box.
I can go right down to the Box category and set some padding. Now here, I just need padding on the bottom. So I'm going to deselect Same for all. On the Bottom, I'm going to do a padding of 0.25 em, so 0.25 em. I'm not even going to set these other ones. I'm just going to click OK. If I click back in here, you can see, now we've added a little bit of spacing between that headline and little bit of spacing between this headline and its border as well. By using padding, we can control the space between an element's content and the edge of an element. This is particularly useful when dealing with elements that have background colors, just like our links right up here, or background graphics, or when we need to control elements that have borders.
I will discuss Margins and Padding in more detail later in the chapter on layouts since they're also used heavily in controlling CSS-based layouts.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.