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

Using the div tag to create a content container

From: Creating a CSS Style Guide: Hands-On Training

Video: Using the div tag to create a content container

Although we are starting to see how styles can improve the page, and we have attached an external style sheet, a best practice, the page when viewed in the browser is all over the place. In this section, we'll use the div tag or a division tag or what I like to call the box tag to create a layout. First, let's just simply put our I- beam anywhere inside the page. Get your I-beam to show up. Using your Command key, select everything on the page by doing Command+A or Ctrl+A. Take a moment to see what we have actually selected by going to Code view. As you can see we've selected all of the content but not the body tag. The body tag is what the browser displays. Just a reminder, head, instructions; body, what we see in the browser. This is the way we want it to be.

Using the div tag to create a content container

Although we are starting to see how styles can improve the page, and we have attached an external style sheet, a best practice, the page when viewed in the browser is all over the place. In this section, we'll use the div tag or a division tag or what I like to call the box tag to create a layout. First, let's just simply put our I- beam anywhere inside the page. Get your I-beam to show up. Using your Command key, select everything on the page by doing Command+A or Ctrl+A. Take a moment to see what we have actually selected by going to Code view. As you can see we've selected all of the content but not the body tag. The body tag is what the browser displays. Just a reminder, head, instructions; body, what we see in the browser. This is the way we want it to be.

Let's go back to Design view. We're going to use our Common tools up here, right between the table and the image that's an icon that says Insert Div Tag. Click on this button. We want to wrap this tag, the Division tag or what I like to call the box tag around the selection. We want to give it an ID name. Let me explain what an ID is. Remember a class can be used as many times as you want on any one page. An ID name can only be used once. Therefore, if you're doing good semantic coding, you'll use an ID name to define or to identify a layout element or a content area on your page.

In this case, we're creating this division or box to hold our content, so the ID name will be content. To emphasize again, you can only use this ID or this content name once per page. Let's click OK. As soon as we do that, we see something a little bit new, which is this line right here, but it's easier to understand if we choose Split view. So I'm going to select Split view, move my view so there parallel, side by side. We can see that we have nested the div tag inside the body tag.

We now have a box or a tag that surrounds all of the content that we've created so far. If I scroll to the bottom, you can see that the closing div tag shows up right here. As we start making more and more complicated layouts, this becomes very, very confusing. You can end up with three or four closing tags for divisions at the bottom and not know what they're closing. So as a best practice in a standard that I like to use, let's put our I- beam right before this close tag and on the left you'll see two things that look like we're designing cartoons, but actually they are a way to insert comments inside your HTML code.

This is also a great way by using commenting to remind yourself what you actually were thinking about and trying to do as you worked on this page. So select this button and choose Apply HTML Comment. Don't touch anything. Just where that I-beam is, type close content. This will let you know that this closing tag is for the box or division called content. If at some time you decide to eliminate this entire div tag by putting the comment within the tags, it makes it easy to remove everything at the same time. Let's select Design view. Let's scroll to the top and let's just hover over this line again if you want to see that box or that division, just click on this line. Right now there is no styling attached to this content division box, so it just indicates it with a dotted line.

So we've created a box or division around this content, but we have no styling on it, let's create some styles for our content div. Just put your I-beam again into your document, go down to your Tag Inspector and now you can see there is our body tag, and there is our division tag. This is a good example of using the JavaScript hash mark. The way to read this is this is a division tag that goes by the name or ID of content. So let's select this tag and that will select that tag and everything that is inside of that tag.

Now we are ready to start styling. Over in the CSS panel on the right, select New CSS Rule. This time, Dreamweaver has done an excellent job of guessing what we're doing, because we have selected a tag that has an ID name, it says you're trying to do an ID type of CSS rule. It also reminds us that an ID can only be used once per HTML page. It identifies the ID, which is #content. In order to style this division, we need to include the hash mark. This is what differentiates it from a class or a tag style. Tags have nothing in front of them, classes have a period and IDs have the hash mark.

Finally, we want to define our styles inside our external style sheet. Select OK and click. Up comes our CSS Rule Definition dialog box. Now this is a little confusing for beginners. But when we want to style a division tag or as I've called it a box tag, don't select Block, Block refers to blocks of type. Everything listed in here has something to do with body, text, paragraphs, blocks, something you would do in a Word editor.

For layout, we want to choose box. So the way I like to think of it is division is sort of synonymous with box. A division is a box. I want my box to be the same width as my header image. My header image is 780 pixels. I carefully chose 780 pixels because it would display well in an 800x600 viewport and I thought it would look good on most people's monitors, in most browsers. I will not define Height. Because unlike print documents, I really don't know how much content will appear on this page and I want the content to be able to flow. If I add more content, it will be longer. If I have less content, the page will be shorter. So I'll leave this one empty. But I do want to deal with the Margins, I'm not happy about the Margins. Right now, I'm going to move this down, so we can watch what goes on with the margins.

In the Margin area, deselect Same for All. I still want the page to be at the very top of the browser, so I'll leave that at 0. But there is a value that's very important that we can use called auto and I'm going to select auto for the Right and Left Margins. I'm going to put 0 at the Bottom. Auto is a great and powerful value. What auto means is that when your page displays in the browser, it will automatically try to adjust itself so that the amount of margin on each side, outside of the page is the same. I'll go ahead and click the Apply button, and you'll notice it moved over a little bit.

But you really won't see the full effectiveness until we go out and look at this inside of our browser window. So let's do that. Click OK, choose File > Save All, choose to preview in your browser and choose Firefox. Let's demonstrate how the auto margin works. It already looks better, because our content is centered and we do now have some breathing room, some negative and positive space. As I change the viewport size, notice that the margins on either side of the header image stay the same. This is a great, great way to make your pages look good inside the browser window. Let's look at our page for one more moment while we're in the browser, what else could we do now.

It would be great if we could separate our background area from our content area, by changing the color of these two backgrounds. The background of the body right now is this light gray green. Could we go ahead and change the background color for our content area? Let's go back into Dreamweaver and try doing that. Close your browser window, we focus on Dreamweaver. When you want to reedit a style, all you have to do is go to your CSS Style panel and double- click on that style. This opens up our familiar CSS Rule Definition dialog box, and we just discussed how it would be easier to see the content if the content area had a distinct background color from the background of the body tag.

Select Background and inside of Background-color choose white, and then select the Apply button. Already looking better and let's click OK, File > Save All, preview this out in the browser one more time. Looks good! Now there is one other thing we need to do which is basically an IE Fix or Hack. The older IE browsers don't display this exactly right. So we're going to go in and add something that will position our text and our body tag and our backgrounds the right way. So I'm going to teach you this little fix, it's a good one to know, it's still used a lot. Until everybody gets up to these new web standards, browsers, we have to do this.

Let's close Firefox, refocus on Dreamweaver. Let's double-click on the content ID, bring up our dialog box. This time I do want you to select Block. This has to do with the way old IE browsers display text inside of Block, select Text-align and choose left alignment. Go ahead and click Apply, you won't see a change. This is just a fix we're making. Firefox displays this correctly. Scroll up to the top of your Style panel, select the body tag, double-click to open up the Style dialog box. Again, select Block, and in the body tag we need to make Text-align centered. Go ahead and click Apply. Again, it's not going to make a difference. We're previewing in a more contemporary up-to-date web standards-compliant browser.

Again, choose File > Save All. Make sure that the changes you've created in here also work in the browser. Choose your browser, Firefox, looks really, really good, just the way I wanted. It still needs a little work. We need to work on our margins and padding, but we can do that using our styles. Crawling the content inside of div tag has made a difference. We have better readability, we have good hierarchy of information and the positive and negative space has given our page breathing room in a way to see our side and to make our eye wander through the site the way we want it to.

We're on our way to creating a great style guide that our website design team can use for designing their website.

Show transcript

This video is part of

Image for Creating a CSS Style Guide: Hands-On Training
Creating a CSS Style Guide: Hands-On Training

35 video lessons · 28026 viewers

Laurie Burruss
Author

 
Expand all | Collapse all
  1. 6m 58s
    1. Welcome
      1m 9s
    2. Objective of this course
      3m 38s
    3. Using the exercise files
      2m 11s
  2. 28m 26s
    1. Starting Dreamweaver for the first time
      3m 38s
    2. Defining a website
      4m 3s
    3. Understanding the Dreamweaver interface
      9m 43s
    4. Setting up a custom workspace
      4m 10s
    5. Setting essential preferences
      6m 52s
  3. 56m 54s
    1. Laying out a page in a text document
      3m 40s
    2. Creating and saving a new document
      3m 27s
    3. Inserting an image
      8m 22s
    4. Marking up text using the Property Inspector
      6m 48s
    5. Marking up text by hand
      9m 21s
    6. Inserting, formatting, and selecting a table
      8m 16s
    7. Creating links
      12m 26s
    8. Styling a footer
      4m 34s
  4. 22m 15s
    1. Using Modify Page Properties to create embedded styles
      12m 22s
    2. Creating links with CSS
      4m 55s
    3. Working with Code, Split, and Design views
      4m 58s
  5. 8m 52s
    1. Defining browsers to test a web page
      2m 24s
    2. Previewing a web page in a browser
      6m 28s
  6. 16m 44s
    1. Using a span tag to add a class and customize appearance
      10m 34s
    2. Using the Tag Inspector to create and edit additional styles
      6m 10s
  7. 48m 42s
    1. Exporting existing styles into an external style sheet
      7m 0s
    2. Using the CSS Styles panel to add a new style
      5m 43s
    3. Using the div tag to create a content container
      11m 8s
    4. Overriding the default browser styles
      2m 46s
    5. Applying padding and margins
      4m 57s
    6. Styling header tags
      5m 34s
    7. Creating and styling compound tags
      5m 12s
    8. Editing preexisting rules
      6m 22s
  8. 19m 36s
    1. Improving the Footer
      5m 12s
    2. Commenting a CSS style sheet
      7m 0s
    3. Creating a custom color palette
      7m 24s
  9. 3m 6s
    1. Style sheet final review
      3m 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
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

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.


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.

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 Creating a CSS Style Guide: Hands-On Training.

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


OK
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
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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

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.