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

Building navigation with CSS

From: Dreamweaver CS3 Beyond the Basics

Video: Building navigation with CSS

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.

Building navigation with CSS

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.

Show transcript

This video is part of

Image for Dreamweaver CS3 Beyond the Basics
Dreamweaver CS3 Beyond the Basics

102 video lessons · 38690 viewers

James Williamson
Author

 
Expand all | Collapse all
  1. 2m 3s
    1. Welcome
      1m 17s
    2. Using the exercise files
      46s
  2. 1h 23m
    1. Reviewing the Coding toolbar
      8m 42s
    2. Customizing the Coding toolbar
      9m 52s
    3. Taking advantage of Code Hinting
      7m 20s
    4. Using snippets and shortcuts
      11m 10s
    5. Using the Quick Tag Editor
      5m 18s
    6. Using Find and Replace
      9m 50s
    7. Regular expressions
      5m 39s
    8. Using Bridge with Dreamweaver CS3
      8m 28s
    9. Round-trip editing with Photoshop CS3
      3m 40s
    10. Leveraging image variables in Photoshop CS3
      7m 32s
    11. Integrating external variables into your workflow
      6m 16s
  3. 37m 26s
    1. Understanding the CSS Styles panel
      7m 59s
    2. Understanding the Cascade
      5m 50s
    3. Understanding Inheritance
      5m 8s
    4. Understanding Specificity
      7m 5s
    5. Managing CSS styles
      5m 4s
    6. Using Design-Time style sheets
      6m 20s
  4. 2h 19m
    1. Using the new CSS template pages
      5m 59s
    2. Understanding DIV tag structure and layout
      12m 0s
    3. Understanding the CSS box model
      10m 0s
    4. Using absolute and relative positioning
      8m 35s
    5. Understanding floating elements
      7m 9s
    6. Clearing floats
      7m 19s
    7. Using floats to control page layout
      3m 45s
    8. Building structure and assigning IDs
      10m 19s
    9. Applying basic styling to structured content
      11m 14s
    10. Positioning container elements
      11m 4s
    11. Enhancing layouts with background graphics
      11m 48s
    12. Creating faux columns with background graphics
      8m 55s
    13. Creating rounded corners with background graphics
      9m 17s
    14. Building navigation with CSS
      16m 57s
    15. Using Dreamweaver's Browser Check feature
      5m 31s
  5. 53m 22s
    1. Creating properly structured forms
      6m 30s
    2. Creating accessible forms
      6m 41s
    3. Using CSS to lay out form structure
      7m 40s
    4. Creating vertical columns for form elements
      7m 48s
    5. Adding user feedback
      5m 52s
    6. Applying advanced styling to forms
      8m 11s
    7. Client-side form validation
      4m 17s
    8. Validating forms with the Spry Validation tools
      6m 23s
  6. 1h 20m
    1. Understanding the Spry framework
      3m 43s
    2. Defining a data source for use in Spry
      3m 56s
    3. Creating a Spry table
      8m 8s
    4. Using the Spry widgets
      8m 11s
    5. Connecting various data sets
      4m 50s
    6. Understanding Spry widget structures
      7m 1s
    7. Applying custom styles to Spry widgets
      6m 24s
    8. Applying additional custom styles to Spry widgets
      8m 46s
    9. Controlling Spry widget behaviors with JavaScript
      6m 0s
    10. Controlling Spry widget animations with JavaScript
      9m 31s
    11. Creating effects with Spry behaviors
      4m 42s
    12. Hand-coding Spry
      9m 11s
  7. 1h 11m
    1. Creating a base template
      8m 6s
    2. Creating editable attributes
      6m 26s
    3. Creating a new page from a template
      7m 42s
    4. Applying a template to an existing page
      4m 36s
    5. Creating nested templates
      5m 24s
    6. Using repeating regions
      6m 34s
    7. Creating editable and non-editable optional regions
      6m 0s
    8. Using template parameters
      7m 26s
    9. Using template expressions
      9m 59s
    10. Using conditional template expressions
      8m 54s
  8. 54m 40s
    1. Examining XML structure
      2m 44s
    2. Creating an XML document
      9m 9s
    3. Using the CDATA structure
      5m 7s
    4. Creating an XSLT file
      4m 33s
    5. Binding data from an XML to an XSLT document
      5m 6s
    6. Inserting repeating regions into an XSL document
      5m 16s
    7. Creating a client-side XSL transformation
      2m 52s
    8. Styling a remote RSS feed
      7m 29s
    9. Creating a server-side XSL transformation
      5m 31s
    10. Writing XSL expressions
      6m 53s
  9. 1h 2m
    1. Overview of building dynamic websites
      1m 35s
    2. Installing PHP, MySQL, and Apache on Mac
      3m 22s
    3. Installing PHP, MySQL, and Apache on Windows
      3m 54s
    4. Creating a MySQL database
      3m 16s
    5. Defining a testing server and database bindings
      6m 14s
    6. Creating a database recordset
      4m 35s
    7. Adding dynamic content to the page
      5m 14s
    8. Creating repeating regions of dynamic content
      7m 6s
    9. Filtering database records
      7m 39s
    10. Using the Live Preview
      10m 22s
    11. Passing URL parameters
      4m 23s
    12. Dynamically generating links
      5m 18s
  10. 57m 9s
    1. Understanding behaviors
      5m 16s
    2. Installing additional behaviors
      3m 39s
    3. Planning to create a custom behavior
      3m 42s
    4. Examining existing behaviors
      5m 32s
    5. Building a behavior function
      7m 23s
    6. Creating an Action file
      6m 48s
    7. Enabling behavior functions
      9m 1s
    8. Initializing the user interface for a behavior
      3m 9s
    9. Loading behaviors in Dreamweaver
      6m 47s
    10. Testing and debugging behaviors
      5m 52s
  11. 27m 12s
    1. Running reports
      7m 41s
    2. Checking and validating links
      3m 40s
    3. Using cloaking
      5m 42s
    4. Using Check In/Check Out
      4m 3s
    5. Using Design Notes
      6m 6s
  12. 20s
    1. Goodbye
      20s

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.

Join now "Already a member? Log in

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 Dreamweaver CS3 Beyond the Basics.

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.