Start learning with our library of video tutorials taught by experts. Get started

Exploring CSS Positioning

The CSS box model


From:

Exploring CSS Positioning

with Candyce Mairs

Video: The CSS box model

What we're going to take a look at now is the most important concept in CSS Positioning. And that is, the CSS Box Model. Right now, I'm within the Code tab within the Coffee Cup editor. And what I want to do is go back to My Websites. Within the course files, I do have a file that can be used to demonstrate and play with the CSS Box Model. And it's appropriately named the CSS Box Model.
Expand all | Collapse all
  1. 1m 13s
    1. Welcome
      1m 13s
  2. 33m 20s
    1. Why CSS positioning?
      5m 50s
    2. HTML editors
      3m 18s
    3. Getting set up
      3m 39s
    4. Previewing pages in browsers
      3m 51s
    5. Customizing the HTML editor
      5m 32s
    6. Exploring browser variances
      5m 16s
    7. Browser extensions
      5m 54s
  3. 30m 33s
    1. HTML vs. CSS: Which does what?
      9m 55s
    2. HTML div tags
      4m 57s
    3. CSS properties
      6m 21s
    4. The CSS box model
      9m 20s
  4. 28m 46s
    1. Planning the page layout
      3m 47s
    2. Building the header box
      6m 23s
    3. Positioning with HTML
      3m 36s
    4. Positioning with CSS
      8m 21s
    5. Foreground vs. background content
      6m 39s
  5. 25m 44s
    1. Building the menu box
      5m 7s
    2. Adding the menu links
      4m 58s
    3. Formatting the menu with CSS
      6m 43s
    4. Positioning the menu with CSS
      8m 56s
  6. 21m 42s
    1. Adding the middle column
      6m 29s
    2. Creating a CSS rule for the column
      6m 20s
    3. Adding CSS rules for the column
      8m 53s
  7. 19m 49s
    1. Adding the right column and inserting images
      7m 33s
    2. Completing the right-column content
      4m 18s
    3. Formatting the right column using CSS
      7m 58s
  8. 26m 14s
    1. Understanding the float property
      6m 5s
    2. Applying the floats
      6m 1s
    3. Finishing the floats
      6m 24s
    4. Adding CSS properties to the right column
      7m 44s
  9. 30m 59s
    1. Setting up for background colors
      5m 49s
    2. Adding a footer
      8m 50s
    3. Adding the background colors
      7m 20s
    4. Positioning the footer
      9m 0s
  10. 16m 38s
    1. Comparing the web page to the graphic design
      6m 50s
    2. Adjusting the web page as needed
      4m 25s
    3. Adding the final touches
      5m 23s
  11. 2m 43s
    1. Closing thoughts
      2m 43s

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
Please wait...
Exploring CSS Positioning
3h 57m Beginner May 24, 2012

Viewers: in countries Watching now:

CSS enables you to control the look and layout of a web page much more precisely than you could with HTML alone, but it can be time-consuming to learn. In this workshop, expert developer Candyce Mairs makes styling a quick and easy process, walking you through the process of adding content to a web page and using CSS to position that content. Candyce explains CSS positioning concepts like the CSS box model, floats, and clears and demonstrates how HTML and CSS work together to create the look of your web page. By speaking the same language as the browser, you can learn to work with the browser to place content accurately and easily.

Topics include:
  • Previewing pages in browsers
  • Customizing the HTML editor
  • HTML vs. CSS: which does what?
  • Building the header area
  • Adding the navigation menu
  • Positioning using a float
  • Adding background colors and images
  • Comparing the web page to the graphic design
Subjects:
Web Web Design video2brain
Software:
CSS
Author:
Candyce Mairs

The CSS box model

What we're going to take a look at now is the most important concept in CSS Positioning. And that is, the CSS Box Model. Right now, I'm within the Code tab within the Coffee Cup editor. And what I want to do is go back to My Websites. Within the course files, I do have a file that can be used to demonstrate and play with the CSS Box Model. And it's appropriately named the CSS Box Model.

And what I'm going to do is open up this page. And let's take a look at the code within the page, and how it's set up. And then we'll move out to the Firefox browser, and take a look at it and play with it using Firebug. So, right now, down within the body of our page, we have a DIV tag. We have an outer DIV tag and notice this is inside those two tags. So our header box is sitting inside our outer box. Now, that's the HTML side of things.

If I move up to the CSS piece. I have the outer box defined in CSS. It has a width of 700 pixels, a height of 500 pixels, and it is gray. Our header is very similar but it has a light blue background, so you can distinguish between the two. This pound sign in frotn of the name of that ID tells CSS it's an ID we're referencing.

And this entire piece in front of the curly brackets is known as the selector. So let's go take a look at this page in the Firefox browser. And the reason I'm choosing that browser is because I want to use Firebug, which I've installed within Firefox. It's a very handy way to visually demonstrate the CSS Box Model. So here is my header box, which is light blue. And that is located inside my outer box. So I'm going to turn on Firebug.

Now this is a Firefox extension that I installed separately from Firefox. I also put an icon up here. When you first install it, the icon is down in this bottom right corner. And I know its somewhat difficult for you to see that I'm doing that so I moved it up to here. So, click on that. What firebug does is give you some options for working with your web page. So the web page is up at the top and Firebug is down at the bottom. And what I'm going to do is click on the Layout tab over here. And what this does is show me the box model.

The idea behind this is everything is a box in the HTML window. This box has as an interior size, and right now this is showing us that our page width is 1247 pixels. Now if you notice as I move around, things kind of show up differently. I'll explain that in just a minute. The idea behind this is our box is 1247 pixels wide. The box that's being shown is the entire webpage we're looking at because I have the entire body text selected. What I'm going to do is open this up, and if I click on this div tag. Notice my box is now 700 by 500.

Which is the exact size of the outer box div. And you can see when I select that, it shows you it's exactly 700 wide. If you look at the ruler, when I cover over this, you'll see it's out to 700. As I hover over different features in the browser window. This automatically gives me the information for them. And if I click on the word div, or whatever the tag is, it shows me that specific information. So right now my Header Area is 700 pixels wide.

So notice that once I have the Header div selected. It just shows me this tiny little box in the middle. Every box of content on your web page including every HTML tag also has padding features, border features, and margin features. And we refer to those specific features as properties when we're talking about CSS. So my box has a width of 700, padding is 0, border and margin are the same.

Now watch what happens to my box, I can literally edit it right here. So, I'll make my left padding 20. Now notice what Firebug did, it added a style of 20 pixels of padding. And note what happened to my box, it is bigger now than the outer box that contains it. And that's because, padding added 20 pixels of width to the 700 width that my content is. So, if I reset my width here back to 680, in other words, I added 20 pixels of padding.

So, if I want to keep it within a 700 pixel area, I need to subtract that 20 from 700, and now my box still takes up 700 pixels of width, and you can see it does. Now let me reset the content area here, back to 700. And let's take a look at what happens if I add a border of 5. I add a margin here, let me do the left side, and let's do a margin of 20 as well.

I've added a border, looks like my border didn't stick, of 5. Now, how wide is my actual box? And then I could do the same thing over here, border of 5. This one I'll add. Let's see, this one was was 20 on the other side, and I also need a right padding of 20. Now, the width of my box did not change. Notice it still says 700. But it is not taking up 700 anymore, it's taking up a lot more than that. And each one of these colors represents that specific property. You can see as I move around here, it shows me different pieces. So how come my box is now so wide? Anytime you add padding, border, or margin to a box.

You are adding to the width that, that box takes up within the browser window. You are not changing anything with regards to the width. So I have added 20 plus 20, plus 20, plus 20. So I've added 80 pixels of width to my box. So it's actually taking up 780 pixels. Now if I want to make sure. That my header stays within the 700. I have to take that 80 and subtract it from my width here. So if I subtract 80, go down to 620, notice, now my box is contained. Here's my 20 pixels of padding on each side.

What you have to keep in mind when you are planning your pages is if you plan to add padding, border, or margin to any type of content. You must take that into account when you set up your width. And I'll set this back to 700. Whoops don't think we need 7,000. And I'll delete these, set it back to 0. Now I am editing right within the browser here so what that does is allow me to play with this page but it does not affect my actual page within whatever editor I'm working in.

I'm just playing with this version of the page. So if I had kept these with those changes it would not have changed my actual web page. It just allows you to play and visually see what's going on. This is a great debugging tool. In case things are not working the way you want, just open up Firebug and it allows you to help debug what's going on within your CSS. But that is the CSS Box Model, when planning out your webpages, based on your designs, just keep in mind, you have to reduce the width every time you add padding, border or margin.

Or your actual page content will expand beyond the width. So that is the CSS Box Model in action.

There are currently no FAQs about Exploring CSS Positioning.

Share a link to this course
Please wait... Please wait...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Exploring CSS Positioning.

Return to your organization's learning portal to continue training, or close this page.


OK

Course retiring soon

Exploring CSS Positioning will be retired from the lynda.com library on April 24, 2014. Training videos and exercise files will no longer be available, but the course will still appear in your course history and certificates of completion. For updated training, check out CSS: Page Layouts in the lynda.com Online Training Library.


Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

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