Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
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.
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.
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.