Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Regardless of whether or not you are adept at writing your own CSS and HTML, it is very important for you as a web designer to understand how both of those technologies work, especially when it comes to CSS. And so in this movie we're going to be exploring something called the CSS box model and how you can simulate that inside of Adobe Illustrator. And so here on my screen I have a little mockup of the CSS box model, and so basically what we're seeing here is how objects are interpreted on the web as CSS.
These are something that we call divs, and when you create a div on the Internet you have three basic areas that apply to that div. You have the inner portion here, which contains the content as you can see. We also have the out portion, which is something called padding, which helps create a little bit of space inside of the div to sort of cushion the content. That's why you can think of it as padding, it gives you cushion. And then on the outside, this red area here is called the margin area. This is the area that separates the content from other surrounding content elements.
So when we're defining objects on the web we define them as a content area with a width and a height value. We define a padding value to give them a specific amount of padding. Then we define a margin to determine how far other objects will be from this particular object. Now you're also noticing that I have a black stroke right here on this object. That indicates the border. You can also add a border to the element. The border of the element lies on the padding element only though. If you have no padding applied, the border will apply itself directly to the content area.
Applying a border to something with padding applies it on the inside, like this. The border will not go on the outside of the margin area. In most cases, the margin area will actually be a transparent area that is defined simply by a pixel value, so in all actuality all you would probably see if this were a true piece of CSS or an object in CSS, you would actually just see everything up into the border and the red background would not exist. Let's take a look at how we can start to simulate this box model inside of Adobe Illustrator to make it a little bit easier for us to translate our designs over to the development side.
I have open here an example of some sidebar content that I want to include on a blog design that I'm working on. And so what I need to do here is define a content area and then also add some padding to it, add in some colors, and then if I want to, I can also define margins a little bit later. But in this case I think I'm just going to define the content area and the padding to get a better idea of how that works. So the first thing I need to do is select the object with my Selection tool. With that done, I'm going to go up to the Type menu and go down to Area Type Options.
Once I get into the Area Type Options dialog box, I have an option down here at the bottom called Offset and then inside of Offset I have Inset Spacing. And Inset Spacing basically allows you to add padding around the outside of whatever text object you're working on. And if I click Preview and then start to increase the Inset Spacing, watch what happens. I'll crank that all the way up to 20, and you'll notice as I'm doing this the overall width and height of the box remains the same. It's just adding the padding inward. And that's what padding actually is; it's inset spacing.
And so it's also caused my text to sort of overflow and that's okay. I can rearrange this after I get out of this box. But let's say that I wanted to add 20 pixels of space all the way around the outside. Then I enter an Inset Spacing of 20 and I'm ready to go. Now it should be noted here that you can add different amounts of padding when you're working with CSS. You can different padding to the top, left, right, and bottom, but in Adobe Illustrator, you can only simulate the padding through Inset Spacing and that's just a one-shot deal. You get one increment to go all the way around evenly.
And so once I do that, I'm going to go ahead and click OK. And if I need to resize this, I just take this and drag it down and it resizes without any problem. You notice the inset spacing remains the same all the way around, so, pretty neat. Now what if I wanted to add a color to the back of this, because it's going to be a sidebar element, almost like a widget for instance. So let's add some color to the background. I'm going to have to use something called the Appearance panel in order to do this, so I'm going to go up to the Window menu and make sure Appearance is checked. It is. That means it should somewhere over here. And so if I find that I can drag it out into my workspace, and I can start to work with it.
You'll notice that as I have this entire object selected that I get this indicator here indicating I have a type object selected, and that's exactly right. You should think of type objects as a group of things, because this is merely a group of characters together. If you were to double-click on the word "characters," it would actually switch you to the Type tool and allow you to edit the type individually. So by clicking on that Type section, you're actually targeting the entire group. So I'll switch back to my selection tool for a moment and then click on the type to make sure I'm targeting that. And then once I have that selected, I'm going to then add a new fill on top of it.
So I'll click this to add a new fill, and you'll notice when I do that it adds a new black fill on top, and my text actually went from the brownish color that it was to this black fill. Well, the problem with that is it's applied to the text; it's not actually applied to the box. And so what I need to do is change this fill to be applied to the overall rectangle. First of all, I'm going to collapse this up, so I get a little bit easier to read. I'm going to make sure the fill is selected, and you can tell that because it will be highlighted. And then I'll come down here to the fx icon and when I get to the fx icon, I can go all the way up here to Convert to Shape and select Rectangle. And once I do that, I'll click Preview, and you can see exactly what's going on in here.
By default, it's going to give me a relative option here to say extra width and extra height, and that's going to add some extra space on the outside of the padding area that we defined earlier. Now, this is a great way to simulate margin, but if you want the color to simply be maintained within the padded area and not outside in the margin area, then you would actually need to set this to zero. So I'm going to set this back all the way down to zero, and you can click or you can simply enter in the value zero. No big deal either way.
And so now this is constrained within the padded area and I've got the shape set to rectangle. Everything looks good. I'll hit OK. And now I need this fill to be behind the text, because right now it's overflowing the text. So what I'm going to do is click here and drag this down until I see a little white line appear underneath characters, and then I will release. Once I release that, the text pops back up on top. I can then change the color of the fill by clicking to access this. And let's say I wanted to make this sort of a yellowish color, something like this. Click away, and there we go.
So now I can bring my Appearance panel back over here and dock it on the right, and I've got a really nice representation of what this div would look like in CSS. And so theoretically, this div would be X amount tall by X amount wide, with 20 pixels of padding all the way around it. Now what if we're working in Illustrator and we feel the need to resize this box? Well, if I click and drag out to the right, you'll notice that the box resizes without any problem. If I click and drag down to the left, it resizes without any problem as well.
So you can actually control the width and height of the box without skewing the text, simply by clicking and dragging around just like you would any other object. That inset spacing remains the same no matter what you're doing. So this is a great way to sort of simulate the actual CSS layout inside of your Illustrator mockups by utilizing inset spacing and also converting these fills to the shape of a rectangle to add a little bit of color or even add some margin space to the outside as well.
So the next time you are mocking up things inside of Illustrator, try to utilize this technique to simulate this box model, and you'll be really glad you did, especially when you start to take this into your CSS. Or if you hand it off to a developer and they take a look at it, they'll be able to say "oh, okay he's got 20 pixels of inset spacing. That equates to 20 pixels of padding." It just makes it easier for everybody all the way around.
Get unlimited access to all courses for just $25/month.Become a member
119 Video lessons · 50739 Viewers
117 Video lessons · 38410 Viewers
113 Video lessons · 81475 Viewers
65 Video lessons · 11357 Viewers
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.