New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Simulating the CSS box model

From: Illustrator CS5 for Web and Interactive Design

Video: Simulating the CSS box model

If you are eventually going to code your page using HTML and CSS, it can be helpful when you are creating your mock-ups and your designs inside of Illustrator to be able to visualize how that's going to actually be created. For example, when working with content, it can be helpful to understand what's called the CSS box model. It's a way basically I can build layout using CSS. And in fact, in this layout that I have designed here inside of Illustrator, you can see that these sidebars that have been created are actually single objects. If I click and I move them around, notice that the background color and the text all moves as one unit.

Simulating the CSS box model

If you are eventually going to code your page using HTML and CSS, it can be helpful when you are creating your mock-ups and your designs inside of Illustrator to be able to visualize how that's going to actually be created. For example, when working with content, it can be helpful to understand what's called the CSS box model. It's a way basically I can build layout using CSS. And in fact, in this layout that I have designed here inside of Illustrator, you can see that these sidebars that have been created are actually single objects. If I click and I move them around, notice that the background color and the text all moves as one unit.

These are not individual objects. I don't have here a group with some text in the background. It's actually one area text object, and I have built it in a way to stimulate the CSS box model, and it will help me visualize how I am eventually going to build this using CSS. So in this movie, I want to take a few moments to teach you how to build these types of constructs inside of Illustrator. I am going to start here by creating a new document, because the first thing I want to show you is exactly what the CSS box model is, just to give a basic idea of what we are talking about here. I take a rectangle here, and just draw a larger rectangle like this.

Maybe I will just draw another one out here. I am just going to draw a series here of rectangles, and I will get rid of the stroke here on the inside one. Let me select this middle rectangle here. Let's call this one like a darker gray, and then let's increase the stroke weight just a little bit, and then let's take this outside one here, get rid of the stroke on this one and give this a fill of a lighter gray. So what we have here basically is the basic concept of what the CSS box model is. Whenever you create an area, or what we call a div, inside of a layout using CSS, we have our content that kind of fits inside of it, and then we have an area here that we call a margin area.

It's basically how far away your content can come towards the edge of the div. Then you also have an area which we define as our border, so inside of Illustrator, we think of this as a stroke for example, and then you have an area on the outside which we call Padding, and this padding allows us to offset this div from the other areas as well. So we basically have these distinct areas here. We have our content, which is in the middle, we have margin area, we have a padding area, and of course, over here, we have the actual border itself.

So let's take a look at how we can actually build content in Illustrator to simulate this so that we can better visualize how to build things later on using CSS. So I am going to go ahead, and I am going to delete these objects right now. I am going to start with a regular text object here. I am going to create an area text object. I am just going to click and drag to draw the frame, and I am going to put some text in there. Here is some text. Again, it doesn't make any difference really what the text is now. We can apply text with a paragraph style that maybe we have created, but remember, eventually this text will be populated using HTML.

But for now I am just going to make this text little bit bigger. Here is little bit of a keyboard shortcut, Command+Shift +Greater Than Sign, or if you are on Windows that will be Ctrl+Shift+Greater Than Sign. Makes your text two points larger at a time, so I am going to go ahead and make that just a little bit bigger. And now we are going to start to work on our settings. So I am going to switch over here to my regular Selection tool, and I am going to go over here to the Type menu and choose Area Type Options. So the first that we are going to talk about is the margin setting. Remember, the margin setting was the area towards the inside of the border that allows us to kind of offset the text a little bit from the edge, or the border of the div.

So, if I click on the Preview button here on the Area Type Options dialog box, we will see that I have something here called Inset Spacing, and if I go ahead now when I start to increase that value, you can see that right now I am kind of moving the text towards the inside of this shape. So let's say I do 20 pixels here, for example. That means that I am creating, or I am simulating, a margin setting of 20 pixels. Now it's important to realize that in CSS you can have offset values that are different for top, bottom, left, and right. But here inside of Illustrator, we only have one uniform Inset Spacing setting, which basically is being applied to the entire shape itself.

Still, many times we want our margins to be the same way that way. So again, here inside of Illustrator, I am using the Inset Spacing setting to simulate the margin setting that I would have inside of CSS. Great! So I have done the first of them, and I am going to click OK to accept that value. Now let's talk about actual padding. That's the area towards the outside of the border that allows us to better make sure that there is enough space between the divs, for example. So I have now this shape over, and what I am going to is come over to my Appearance panel.

It's important to realize that inside of Illustrator, we can use the Appearance panel to modify the appearance of Artwork. Now, there is a concept of something called a group inside of Illustrator, and if we think about it, any text object inside of Illustrator is really a group. If we think about each of the characters in this text. For example, the capital H, the e, the r and the e, those are like individual objects, but if we think about a type object as a whole, that is a group that contains all these characters inside them. And in fact, if you look at the Appearance panel, we see that the bold word over here, what we call our target, is right now this type object, and there are characters inside of that.

In fact, if you double-click on Characters, it is if you are targeting specifically the text, and notice that Illustrator changed to my Type tool and highlighted the text using the Text tool. But if I use the Selection tool and I click on it, Illustrator goes ahead and targets the entire type object. Again, think of it as some kind of a group. So what I want to do now, if I wanted to simulate some kind of a color here in the background, what I can do is I am going to now create a separate fill on this group, which I am going to send behind the characters. And I am going to use that to define this other background area, which will become our padding.

So the first thing I am going to do is I am going to come over here, at the bottom of the Appearance panel, with my Type object selected, I am going to choose to add a new fill. Now, right now, this color is picking up the color of my text, which is black, but I can change this to any other color. So just for now I am actually going to change it to, let's say, this red color right now. I want to choose just a bright red color. Now I added now a second fill, so the red fill right now is covering over it. It's on top of the black fill so my text appears as if it's red. But here is the thing: right now, my text object exists, and Illustrator is using that red fill color for the text, but I want the red fill color to actually show the background of this shape of the rectangle, which I want it to be, for example, my div in my CSS layout.

So what I need to do is convert that text somehow into a rectangle. Well, Illustrator has such an effect. So the first thing I am going to do, again, staying in my Appearance panel here, I am going to click on the fill, so that the fill is now highlighted. See now how the fill is selected? I can now come to the bottom of the Appearance panel and click on the Fx icon and choose Convert to Shape > Rectangle. Now I want the rectangle to be a certain size. By default, Illustrator allows me to create what we call a relative width and height, meaning that I now have a certain dimension of that text frame.

Right now, the text frame has a width of 303 pixels and a height of 197. Illustrator is now adding 18 pixels to the both sides of the width over here, so to the left and to the right, and it's also adding 18 pixels as far as the height right over here. Now if I wanted to make it 20, I could just type in 20 over here, hit the Tab key, and type in 20. It's kind of an odd thing here. If I hit Tab again to accept that value, Illustrator thinks I am tabbing to the next value, which is here, and it sets its Absolute. So I am just going to go ahead and make sure that I click on Relative.

So right now I have an Extra Width of 20 pixels, and Extra Height of 20 pixels, which in my mind I could start to think of an extra width or an extra height, or basically extra 20 pixels of padding that now exists on the outside of the border area. So I am going to click OK, but you can see that right now this fill is covering over the text. I can't see the text. So if I look at my Appearance panel, the Appearance panel always displays artwork in the order in which it's drawn, and Illustrator always draws things in the bottom up.

So right now you can see that my fill is on top of the characters. It's covering over the characters. I am going to take this fill and drag it so that it now appears beneath the characters, and now I have some text with this color in the background here. So what I have basically now is the padding that I specified, I have the margin area that I specified, and if I wanted to also add a border here, what I would do is I would come here to the Appearance panel and then target the stroke. And remember, if I just add in a stroke here, it's going to add a stroke to the text.

So I need to do a similar concept here for the stroke, I need to, with the stroke target it, add also a Convert to Shape, Convert to Rectangle effect. In this case here, I want the Extra Width to be set to 0, meaning that my border now is going to be the exact same size of my rectangle. I am now going to change that to a weight of one, and now you can see that I have basically my area on the inside. This is my content. This is my margin area. This is my border area, and this is my padding area. So in this way, I can build Artwork to simulate this CSS box model to better visualize how I want my layout to be.

Now there is one other thing to note here. I have, currently, right now, my bounding box turned on, so if I go to the View menu here, there is an option that says Hide or Show Bounding Box. So with my Selection tool right now, I can change the size of this frame as I need to, and remember the padding, and the margin are always going to remain set to those 20 pixels the way that I set them. Because I have the Use Preview Bounds option turned on - remember we set that preference way back in the beginning of this video title - I am now seeing the actual size of this, where it says Width and Height that is taking to account both the padding and the margin also.

So I am seeing a true value that's right here. However, if I wanted to adjust the width right now, change it to, for example, 400 pixels if I did so through the Transform panel, the text is also going to get stretched. Now we don't want that. We want the frame to get bigger, but we don't want the text to get stretched or distorted as well. Well, there is two ways to do this, actually. I am going to press Undo. If I know for sure that I want the width here to be 400 pixels, I can go to the Type menu and choose Area Type Options, and enter a width of 400. However, when I do that, that does not take into account the extra 20 pixels of padding that exists on the left and right. So we can see over here, the Width is 440 because I am seeing an extra 20 on either end over here.

So the way that you can actually change the size here is to switch to your Direct Selection tool and then just click on just one of the sides of the object. Now change this, for example, to maybe let's say 350, and when I do so, I am able to adjust it without stretching the text. So going back to the page design document over here, that's how I build these areas right here, or the sidebar content, by basically taking an Area Type Object and using a fill that I sent that to the background that I converted to a rectangle, and also using the Inset setting for the Area Type Object to simulate the concept of both padding and margins in the CSS box model.

Show transcript

This video is part of

Image for Illustrator CS5 for Web and Interactive Design
Illustrator CS5 for Web and Interactive Design

74 video lessons · 23662 viewers

Mordy Golding
Author

 
Expand all | Collapse all
  1. 6m 56s
    1. Welcome
      1m 33s
    2. Choosing Illustrator for web and interactive design
      2m 54s
    3. Illustrator and the web design workflow
      2m 7s
    4. Using the exercise files
      22s
  2. 40m 9s
    1. Pixel dimension vs. resolution
      4m 14s
    2. Pixel Preview mode and anti-aliasing
      5m 39s
    3. Taking charge of anti-aliasing
      5m 27s
    4. Choosing the right color management settings
      7m 25s
    5. Setting up important preferences
      6m 22s
    6. Setting up a workspace optimized for web design
      11m 2s
  3. 54m 5s
    1. Using the Web document profile
      3m 39s
    2. Creating custom document profiles
      9m 38s
    3. Using Illustrator's free web templates
      2m 33s
    4. Creating a sitemap or wireframe
      2m 50s
    5. Setting up an entire web site
      9m 33s
    6. Setting up a grid
      10m 37s
    7. Setting up an online ad campaign
      8m 13s
    8. Setting up icons for iOS
      2m 24s
    9. Setting up mobile content with Adobe Device Central
      4m 38s
  4. 32m 22s
    1. Understanding web-safe colors
      11m 50s
    2. Limiting the Color Guide to web-safe colors
      4m 53s
    3. Using Recolor Art to convert art to web-safe colors
      4m 54s
    4. Getting color inspiration from Adobe Kuler
      6m 48s
    5. Using Recolor Artwork to modify colors across a site
      3m 57s
  5. 56m 54s
    1. Using the Save for Web & Devices feature
      6m 44s
    2. Understanding the GIF file format and its settings
      10m 20s
    3. Understanding the JPEG file format and its settings
      7m 39s
    4. Understanding the PNG file format and its settings
      3m 21s
    5. Understanding the WBMP file format and its settings
      1m 18s
    6. Understanding the SWF file format and its settings
      4m 13s
    7. Understanding the SVG file format and its settings
      3m 41s
    8. Adjusting the dimensions of a graphic
      4m 46s
    9. Optimizing files to a specific file size
      4m 5s
    10. Modifying Save for Web & Devices output settings
      6m 51s
    11. Previewing content in Adobe Device Central
      3m 56s
  6. 56m 6s
    1. Setting point type in Illustrator
      4m 11s
    2. Setting area type in Illustrator
      5m 20s
    3. Formatting text quickly with paragraph styles
      14m 39s
    4. Overriding formatting with character styles
      3m 2s
    5. Controlling text anti-aliasing
      4m 50s
    6. Simulating the CSS box model
      11m 14s
    7. Adding cool reflections to text and graphics
      8m 26s
    8. Applying settings quickly with Graphic Styles
      4m 24s
  7. 35m 56s
    1. Understanding the concept of slicing
      3m 22s
    2. Creating slices manually
      4m 26s
    3. Creating slices from guides
      2m 45s
    4. Creating slices from objects
      7m 33s
    5. Understanding the different slice types
      4m 20s
    6. Applying settings to slices
      9m 20s
    7. Creating hotspots with image maps
      4m 10s
  8. 23m 35s
    1. Exporting static SWF files from Illustrator
      3m 35s
    2. Animated SWF: Converting Illustrator layers to SWF frames
      4m 3s
    3. Animated SWF: Using blends to define motion
      8m 35s
    4. Animated SWF: Adding static artwork to an animation
      3m 24s
    5. Animated SWF: Controlling time within an animation
      3m 58s
  9. 17m 13s
    1. Preserving slices and structure with PSD export
      6m 10s
    2. Working with Photoshop Smart Objects
      4m 35s
    3. Sharing color swatches between Illustrator and Photoshop
      2m 52s
    4. Generating an animated GIF file with Photoshop
      3m 36s
  10. 7m 28s
    1. Exporting HTML from Illustrator for use in Dreamweaver
      3m 31s
    2. Exporting CSS and DIVs from an Illustrator layout
      3m 57s
  11. 12m 37s
    1. Moving art between Illustrator and Fireworks
      6m 25s
    2. Using dynamic shapes from Fireworks
      3m 48s
    3. Sharing color swatches between Illustrator and Fireworks
      2m 24s
  12. 16m 7s
    1. Building files for use in Flash Catalyst
      4m 28s
    2. Creating a new Flash Catalyst project from an Illustrator file
      3m 40s
    3. Copying and pasting artwork between Illustrator and Flash Catalyst
      2m 4s
    4. Roundtrip editing between Illustrator and Flash Catalyst
      3m 36s
    5. Creating Flex skins for use in Flash Builder
      2m 19s
  13. 19m 48s
    1. Understanding symbols: The lifeblood of Flash
      4m 58s
    2. Symbols: Understanding 9-slice scaling
      4m 18s
    3. Setting text that will be used in Flash Professional
      3m 5s
    4. Moving artwork between Illustrator and Flash Professional
      7m 27s
  14. 1m 6s
    1. Goodbye
      1m 6s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold

Are you sure you want to delete this note?

No

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.