Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
Covering diverse topics such as improving workflow and managing CSS styles, Dreamweaver CS3 Beyond the Basics is a hands-on course that teaches users how to move beyond standard, static websites. Instructor James Williamson explores how to increase productivity, interactivity, and accessibility with Dreamweaver. He also discusses how to extend the application's capabilities with XML and XSL. Exercise files accompany the tutorials.
Our final task in styling our gallery page is to tackle the navigation. We want a horizontal navigational bar but currently we have just an unordered list of links and we can see that here in our index background file, we have Home, Shows, News, Calendar, Artists, Gallery Info and contact. So it's just an unordered list of links, if I look at it in Code view. You can see that the UL tag has an ID and it's listed as mainNav and then each of the list items have some IDs as well and that would assist us in styling the current links and we will talk about that in the Templates section. So we will move back into Design view.
You might ask yourself why we put our navigation in an unordered list? Why not just have the links and style each of the links separately? Having the structure of the list, the UL tag and the LI tag and then the A tag inside that, not only gives us styling hooks that the links separately would not give us, but from a structural point of view, these links are all related. They are all part of the navigation bar. So having them as separate elements structurally really doesn't make sense. Placing them inside an unordered list gives them the structure necessary to pass along meaning and information to any agent that's consuming this content.
So now that we understand why they're in an unordered list, let's go ahead and take care of styling them. So we'll switch over to our layout_background.css. Since our list is in header, I will scroll up, so that we find our header styles and there they are. Now, sometimes even when I am in a specific selection, I might be styling something unique to that area and it's not a bad idea to go ahead and put a comment so that you know that you are working on say just the navigation one in the header. So I will go ahead and enter in a comment, remember we can actually do that with the coding toolbar. And I will just apply a CSS based comment there and I usually use a much shorter set of lines for those interior sections. So I am just going to put it main navigation styles, we will end that out. So I don't run it all the way across the screen like I do within the entire section. This is just sort of like a sub-section.
So we will go down and we'll begin styling this. Now, the first thing that I have to do is make the list look not so much like a list. So we'll do a #header ul. So we are going to use the descendant selectors to target the unordered list, the list items, the link tags themselves inside of header element and I will go ahead and open up a curly brace and what we are going to do is we are going to set our margin to 0 and our padding to 0. Now, you might notice that whenever I am typing in 0, I am not passing an explicit value. I am not seeing pixels. I am not seeing ems. I don't really need to pass an explicit value, if it's 0, 0 is just none. Now the next thing I am going to do is I am going to tell the list not to behave like a list at all.
So I am going to choose List Style, and I am going to pass in None and that tells any browser to not render this as a list. So these bullets on the side, that will remove the bullets or if this was a numbered list, it would remove the numbers. Now the margin and padding have already been removed with the wild-card selector at the top of the page. But it's a good idea to go ahead and do that to the unordered list anyway. So we will go ahead and save this and we'll keep going. Now the next thing I need to do is arrange this list in horizontal fashion. To do that, I am going to target the individual list items. Now, a list item is actually a block level element. So I can come in and write a selector that targets #header ul li. So that's saying any list item inside an unordered list inside of a header and we're just going to pass one property into that and we're going to do a float: left. So we're going to go ahead and float that to the left.
Now remember what happens with floated elements, each of these list items is going to be floated. So they will all float to the left of the prior one. So we will save our styles, go back into the index background file and you can see right at the top of the page, each of our links is right next to the other one. They are displayed horizontally now, not vertically. There are no bullet points and there are no indentations that you would normally expect to find in a list. So it doesn't look like a list at all. Now we can concentrate on styling the individual links and not worry so much about the list itself. So we will go back into our layout_background.css file.
So here is where we have to style our links themselves and so we're going to use a selector to target just the links. So we'll do #header ul a. Now, some people like to be a lot more explicit there and say #header ul li a. It really is up to you. As long as you are aware of the specificity of the rule and not worried about some other rule overriding it, you are fine. So we'll go down on the next line and we will type in padding and we're going to do 0 and then a space and then 1. 2ems. Now, when we use shorthand notation like this and we have two values in either margin or padding, the first value is applied to the top and the bottom. So we're saying no padding top-bottom, but the second value 1.2ems is applying left and right. So we are doing 1.2ems padding to the left and padding to the right and that's going to push these elements away from each other.
It's really not going to push the elements away from each other because they are still bud up against each other. But it's going to push the content away from the edge of the link giving the appearance of pushing them away from each other and that allows you -- if you give these a background graphic or some of type of divider like we are going to do, it allows these still to lineup and still have space between them. So we'll go down to the next line and we'll go ahead and apply a font size. I am going to actually do an explicit font size here. So I am not going to do the font shorthand. I am going to do the font size and I am going to do 16 pixels. Now, up until now we've always used ems or percentages and I like doing that because it gives a lot of flexibility to the layout. The user can change their font size and it updates and changes.
When you choose pixels though, you are being very explicit and Internet Explorer specifically doesn't really allow that font size to be changed. Now other browsers will but this sort of sets the font size at a specific size. Now why are we doing that? Well, later on we are going to do an alternate style sheet that allows us to have larger text or smaller text and that works great for the body copy but I really don't want my navigation to be blown apart by increasing the font size of this. So by using 16 pixels, I am explicitly stating a value and not tying it into the percentage based on the body tag. We'll go down to our next line and we'll type in line height and we will go ahead and type a line height of 1.5ems. For those of you familiar with print design, line height is equivalent of leading.
So that's line spacing or line height and by giving it 1.5ems, we are actually sort of centering the text inside this much taller area. So even though we are not giving it any padding top to bottom, giving a line height is going to sort of float it in its own line. So the next line we are going to go down to will be text decoration and the native behavior of links in a browser is to display with an underline. Well, we want to remove that underline because it's really not part of our styling. So for text decoration, we are going to type in None. So if you ever want to get rid of the underline underneath your links, that's how you do it. Text decoration is none. We'll change the color and our color will be #fff which is white. So the text will show up as white.
Now we're also going to do a float: left on our links as well. And what that's going to do for us is it's actually going to make the floated elements display as a block level element and I will describe why that's important in a moment. We'll do display equals block as well and I want to talk about what those last two rules are doing for us. A link tag by default is an inline level element. I mean hovering over the text will activate the element but hovering to the right or to the left of it won't. Well, this is going to be a navigation bar, so we want the entire block that the link tag is inside of to be an active part of the link and in order to do that, it has to be recognized as a block level element.
So the display block are for Internet Explorer or on any other browser that needs that explicit designation, while float left will just go ahead and make it a block level element in Firefox, Safari or other DOM-compliant browsers. So we'll save this and I will switch back over to Design View and now we can see because we've given them a block level designation, Dreamweaver is now giving us a dotted border around that particular element. So you can see how it's kind of floating in the middle of its own box. Now Dreamweaver isn't really rendering Gallery Info properly and that's okay because we know it's going to render in the browser properly. I mean it's just those little design glitches that Dreamweaver has every now and then as it tries to render the styles, but other than the Gallery Info we are pretty happy with the way this is running right now.
So to make this look a little better, we are going to apply a couple of background graphic. So I am going to get back to my layout_background.css and I am going to go back up to my unordered list. So I am going to modify this style by adding a new line to it and we're going to choose the background property and we'll do URL and I am going to browse out and in the images directory I want to find the menu_bg.gif. Now if you select that and look at the thumbnail of it, you can see that it's a graphic that has just a gradient. It's very thin, very small gradient that has a dark red, sort of lighter orang-ish gradient happening in it and that's going to be consistent background throughout my unordered list. So when I select this, I have to pass along a few more values to make it work the way I want.
So I am going to say repeat-x and I am going to position this at the top left which is the default but we're being pretty explicit with that. So we will save this file and the next thing we want to do is we want to go down to the actual link itself. So I am going to get back and modify the header ul a selector and we're going to give it a background graphic as well. Now, that gradient is now going to stretch horizontally all the way across our Navigation Bar. So by applying a background graphic to the A tags, we could bring in a divider graphic. So I am going to add a new line here and we're going to do another background designation and we'll browse again, so you can just type in un and hit Enter and of course Dreamweaver brings this up for us.
Well, we are going to browse and we want to find in our Images directory. We want to find the menu_sep for separator and it's even a thinner graphic. You can see it's only 2 pixels wide by 28 pixels tall and those two pixels have a lighter orange and sort of a darker red bar. So it's going to give us the illusion of having separator between the links. So we'll go ahead and choose that. We'll go ahead and tell this one not to repeat. So we'll do no repeat and we're going to position this along the left top and that will line it up with the top left of each a selector and that should put them in between each one of them.
So we'll save that and we'll go back to index background and check on our progress. Now, first it doesn't look like anything has really happened here. So I am going to preview this in the browser to see what's going on. When I preview this in my browser, my navigation looks sort of kind of the way I wanted. Notice that we have got our separators now in between each of these elements but we're not getting that background graphic and we have got to figure out why that's occurring. So I will go ahead and close Firefox. When we switch back to our layout background file, there is something that we've got to remember from earlier when we were doing floats. Notice that our unordered list items, and our link tags, both contain a float left declaration.
Now, any parent element that has the child elements inside of it floating is going to collapse in on itself unless there is something that can keep it from collapsing. So we do have something that's going to keep it from collapsing and we'll explore that in just a minute, there is one more thing we need to do before we do that however. You may have noticed when we tested it that the Home link, which is the first item, also had that background graphic and we really don't want that. Well, if I look at the actual code itself and I look at that Home selector, notice that it has a class attribute applied to it of first and that's indicating that it is the first link in the Navigation Bar. So we're going to take advantage of that styling hook to tell the background to go away for that particular element. So we'll go ahead and write the selector and I am going to add another selector to the header section and it's going to be #header ul a.first.
So again that's an element specific class selector tied to the ul and the header and this is pretty easy to do. We're just going to pass in a value of background none and regardless of whether you had a color or a background graphic applied, it would just sort of strip that out. Now, while we're at it, we'll go ahead and finish a hover effect as well. Most people that have used CSS before have used the Pseudo Selector. So I am going to type in #header ul a and then add a colon and hover to it and if you've never used that before, there is actually four Pseudo Selectors, there is Link, Hover, Visited and Active and they allow you style different states of your links.
So by saying a:hover, we're saying when the mouse hovers over this, we want this style to appear and it allows you to create really neat CSS rollover effects if you've never done those. So we're just going to add a color for our hover effect and we'll type in #561216 and that's sort of a dark burgundy color. So now when we rollover our links, they will change from white to that color and let's go back and fix the problem we were having with our unordered list and before I do that, I am going to save this and go back to the next background and I will switch over to Design view.
We're going to see that not only is it going to help us solve the problem of the background graphic not appearing but it's also going to solve another problem. Our Navigation Bar right now is sort of floating in the middle as top section of our header and we need it to attach itself down to the bottom. So essentially what we have to do to our unordered list is position it and applying any type of positioning attribute or a float attribute to a parent element will cause it to go ahead and expand and contain any of the elements inside of it including ones that are floated. So not only is this going to help us position our unordered list, but it will also help that background graphic show up because our unordered list will finally have some dimension to it. So we'll go back to layout_background.css and I am going to scroll up in my code just a little bit to find that unordered list and there are just a few properties we need to add to this.
So I am actually going to add these properties underneath the padding. I like sort of putting the positioning attributes up top if I ever have them. So after padding, I am going to type in position and the position is going to be absolute positioning. So since the header container itself is relative position. It will position itself based on the top left corner of the header. So after that, we'll type in left and we'll position the left at 0. That will align it with the very left edge of the container and instead of using a top and trying to calculate how far down it needs to go, I am just going to give it the bottom position attribute and along bottom, I will go ahead and pass along a value of 0 as well. Now what that will do is it takes the bottom left hand corner of your Navigation Bar and lines it up with the bottom left hand corner of the header. So you really don't have to do a lot of math or a lot of calculating if you use that technique.
Now we'll go underneath that and we'll go ahead and give it a specific width as well and regardless of what goes on with the text inside of it, it will keep the Navigation Bar lined up exactly where we wanted which is to end right at the end of the content. So the width of this is going to be 650 pixels. Now, we'll go ahead and save that, switch back to our index background and there is our Navigation Bar. Now, Dreamweaver isn't rendering it entirely correctly because of the fact that it's breaking the Gallery Info. So I will test this in my browser. And as we preview this in our browser, we can see that our Navigation Bar is exactly 650 pixels wide exactly the way we wanted it, but we're still having an issue with the text fitting inside of it. This is one of the reasons why I use an explicit value, so that if somebody were to set their text a high value then our Navigation Bar wouldn't really break like you're seeing a break now.
So we've got to go back and figure out exactly why it's breaking and it's not necessarily the size of the text that's causing it but it's the spacing between them. So when we close our browser, I will go back into our layout_background.css and we'll go and look at the #header ul a rule. So you'll find that on line 64, and the culprit is more than likely the padding and this is a very real world example because as you start to style Navigation Bars and lists and things like that or icons, you are going to constantly be tweaking your values to get it exactly where you want.
So you want to test this in as many browsers as you can. So let's go ahead and fix this. Let's change the padding to 1 .1ems instead of 1.2 and sometimes you will see that the littlest things make the biggest difference. So we'll go ahead and save that. Go back into our index background file. Test that in the browser again. So our Navigation Bar looks exactly the way we want it to look and for all purposes, our layout is done and in our next movie, we'll explore Dreamweaver's Browser Check feature to make sure our layout is going to work properly across multiple browsers.
Find answers to the most frequently asked questions about Dreamweaver CS3 Beyond the Basics.
Here are the FAQs that matched your search "":
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
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.