Creating and Customizing Horizontal Spry Menu Bars in Dreamweaver

by dwcourse on July 14, 2007

If you enjoy this tutorial, you may be interested in our Dominate Dreamweaver training. My 12-week online course which will take your from the Dreamweaver basics through building complex spry menubars and much more.


Click here to learn about Creating and Customizing Vertical Spry Menu Bars…

I should start by saying that Adobe has done an excellent job implementing spry menu bars. More to the point, they have documented the CSS files that control the appearance of the menu bars with ample notes to guide the adventurous. They’ve even included a help file that’s actually helpful. Still, in my experience, a program’s documentation is the last place people look for help so I’ve put together this little tutorial.

Note: For the most part the process of customizing horizontal and vertical menu bars is the same but there are differences so I’ll follow up this post with one devoted to vertical menus. However, if you can’t wait, the instructions offered here should provide a good basis for your own experimentation with vertical menu bars.

Getting started:

Before you begin, make sure you have properly defined your website within Dreamweaver.

Create a horizontal menu:

  1. Open an existing document or create and save a new one. Dreamweaver CS3 won’t allow you to add a menu bar to an unsaved document. If you try, you’ll be prompted to save the document before proceeding.
  2. Select the location in your document where you want the menu bar to appear.
  3. Select the Spry tab in the Insert palette. (if the Insert pallet is not visible, select Insert from the Windows menu to display it.)
    Dreamweaver CS3 Insert Palette
  4. Click on the Spry Menu Bar icon in the Insert palette.
  5. You will be asked to select horizontal or vertical for your menu bar layout. Since we’re making a horizontal menu bar, select horizontal and click OK. Your menu bar will be placed on the page.
  6. Immediately save the document. You will be informed that your menu bar requires a number of supporting files and prompted to save them. Click OK and DW will save the files in a SpryAssets folder it will create within the root folder of your website.
  7. With the menu selected, you can use the Properties palette to define the links, menus and submenus of your menu bar (to select the menu bar, click on the blue box labeled “Spry Menu Bar for xxxxx” that appears immediately above your menu bar).

    Dreamweaver CS3 Menu Bar Properties Palette

    Note that the Properties palette also contains a link, “Customize this widget.” That leads to the Help file that you are hoping to ignore by reading this. Take my word for it, clicking that link will be worth your while. Go ahead, I'll wait for you.

Customizing the look of the menu bar:

Menu Bar CSSGood, you're back. In case you didn't figure it out from the help file, I should let you know that the look of your menu bar is controlled by the styles in the CSS file (SpryMenuBarHorizontal.css) that Dreamweaver graciously created in the SpryAssets folder. Since we'll be editing these styles, you'll need at least a minimal understanding of CSS styles in DW. For instance, you should know - or be able to figure out - that when I say “set width: 20%” you should change the style definition so that the width attribute is set to 20%.

Type style and size:

DW does not specify styles for the text in its menu bars so the style attributes are picked up from the page element(s) that enclose the menu bar. If you would like to use a specific font, size, weight, style, variant or case attribute for ALL the text in your menu bar, specify it in the ul.MenuBarHorizontal style. The color of the text will be defined elsewhere.

Menu bar width:

By default, the width of each menu item is set to 8 ems and the overall menu width is set to auto (determined automatically by the width and number of menu items).

To specify a specific pixel width for a menu bar: In the ul.MenuBarHorizontal style replace width: auto with width: XXXpx AND set the width attribute in ul.MenuBarHorizontal li to an appropriate value in either percent or pixels.

In other words, if ul.MenuBarHorizontal is set to width: 600px and there are four items in the top-level menu, an appropriate setting for ul.MenuBarHorizontal li would be either width: 150px OR width: 25%. For a 600 pixel wide top-level menu with 5 items the appropriate setting for ul.MenuBarHorizontal li would be width: 20% or width: 120px. Just make sure everything adds up or you may get unexpected results.

Note that changes made to ul.MenuBarHorizontal li affect only the items in your top level menu. The width of pull-down menus is not affected. Also, you should avoid adding borders to the ul.MenuBarHorizontal li style. They’ll throw off the width calculations we made above.

Menu bar height:

Caution! You can control the height of your menu bar by specifying a height attribute in the ul.MenuBarHorizontal a style. But be careful. This can cause type to be cropped or even disappear if text is resized or a menu item unexpectedly wraps to a second line.

Color of menu items:

The color of menu items in the link state (when they are not being hovered over or clicked) is determined by the ul.MenuBarHorizontal a style. To change the look of your menu items, simply change the default background-color and color styles DW has provided. This is also the place to add borders if you want to visually separate the menu items.

Rollover color of menu items:

To keep it simple, set the background-color and color styles to your preferred rollover colors in the following two style definitions:

  • ul.MenuBarHorizontal a:hover, ul.MenuBarHorizontal a:focus
  • ul.MenuBarHorizontal a.MenuBarItemHover, etc.

In THEORY, the first definition determines the hover state of menu items and the second definition controls the appearance of menu items with open submenus. In REALITY that’s the way it works in Explorer. However in Firefox and Safari BOTH the hover state and the appearance of menu items with open submenus are governed by the second definition. I usually just make sure both definitions have the same settings for background-color and color and forget about it.

Menu bar arrows:

The way DW menu bars are constructed, menu items which open to submenus have an arrow (downward -pointing for top-level menus, right pointing for sub-menus) at their far right edge. These arrows are actually background images. If you change the background color of menu items or their rollover state, the arrows may become difficult to see.

To change the arrows, edit the background image attribute in the appropriate style definition as described below:

  • Edit ul.MenuBarHorizontal a.MenuBarItemSubmenu for top level menu items with a submenu.
  • Edit ul.MenuBarHorizontal a.MenuBarItemSubmenuHover for the hover (rollover) state of top level menu items with a submenu.
  • Edit ul.MenuBarHorizontal ul a.MenuBarItemSubmenu for submenus with a second-level submenu beneath them.
  • Edit ul.MenuBarHorizontal ul a.MenuBarItemSubmenuHover for the hover (rollover) state of submenus with a second-level submenu beneath them.

For reference, DW makes available the following images in the SpryAssets folder:

  • SpryMenuBarDown.gif – black arrow pointing down
  • SpryMenuBarDownHover.gif – white arrow pointing down
  • SpryMenuBarRight.gif - black arrow pointing right
  • SpryMenuBarRightHover.gif - white arrow pointing right

Looking for More Dreamweaver Tips, Tricks & Tutorials?

If you'd like to receive more tips and tutorials like this subscribe to my Dreamweaver Tutorials newsletter by completing the form below:

Post to Twitter

{ 377 comments… read them below or add one }

1 2 3 4

Kyle February 1, 2012 at 10:32 am

HI There!

I am designing a website for our organization and have it mostly completed. The only remaining issue is that the sub menu’s won’t drop down in any browser. I am at a complete loss as to what to do. Any help would be appreciated!

Reply

dwcourse February 1, 2012 at 10:52 am

If you look at the code of your page you have:

<script src="file:///C|/Users/SJSCI Laptop1/Desktop/Safe Communities/SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="file:///C|/Users/SJSCI Laptop1/Desktop/Safe Communities/SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />

The file:/// at the beginning of the links indicates the link is to a file on your computer. So when the site is accessed on the web it breaks. Generally this is caused by not defining (setting up) your site correctly. I would imagine the links should look something like:

<script src="/SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="/SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />

Reply

Glynne January 25, 2012 at 1:18 pm

Hi Dw

Wonder if you could help me.
Im using an image on repeat as background across the the main navigation of the spry menu.
But, i want to use a plain colour for the dropdown/submenus??
Its currently using the same image im using in the main nav above.
I keep going around in circles with the CSS and cant figure it out??

thanks in advance

Glynne

Reply

dwcourse January 25, 2012 at 1:28 pm

You can use the image as a background in the ul.MenuBarHorizontal a rule.

Then in the ul.MenuBarHorizontal ul a (the second ul means it only applies to links in submenus) rule (you may have to create it) set background-image:none and set background-color to whatever you want.

BTW, if you use the background shorthand property it resets all the background properties. So all you really need to do is:

ul.MenuBarHorizontal ul a {
background: #000;
}

Substituting whatever color you prefer.

Reply

Jaime December 14, 2011 at 12:07 pm

I’m having a problem with my spry horizontal menu bar. It centers on the rest of my page fine in ie, firefox and chrome on my computer at 1280×1024, which is the max res on my machine. However, the menu bar moves to the left on my friend’s mac. His machine has higher resolution, and he runs both firefox and safari and it happens on both browsers.

I built the site with tables, which I know is problematic, but I don’t know how to write code. I’ve tried everything I can think of, including centering the menu between div tags, but nothing helps.

Any ideas? I’m desperate at this point, as my site was supposed to launch dec. 1…..:-(

Reply

dwcourse December 17, 2011 at 12:49 pm

If you are talking about the site at http://zenoutfitters.com then the menu doesn’t change with the resolution, it’s flush to the left of the table.

Reply

Haylee Watson December 13, 2011 at 12:43 pm

I have set the width on the spry menu bar on my dreamweaver site to the appropriate width. It shows correctly on dreamweaver itself, but when viewed in internet explorer, the width is not correct, and the alignment of the spry menu bar is aligned to the left. I have used several codes for setting the width, but none seemed to work. I have adjusted the width on the ul.MenuBarHorizontal and the ul.MenuBarHorizontal li, but the changes do not save on the internet.

Reply

dwcourse December 17, 2011 at 12:50 pm

I can’t really offer any suggestions without the url of a page where I can see the issue.

Reply

yunlu18 November 1, 2011 at 9:50 am

I love the tutorial but you didn’t explain how to fit a gif correctly into a menubar.I tried several times but failed.where to change the picture and what is the size of gif

Reply

dwcourse November 1, 2011 at 9:55 am

Placing an image into the built-in Spry menu bars is problematic. While it’s possible, they are set up to use text links and don’t accommodate images without a lot of customization.

Reply

Tam October 30, 2011 at 1:10 pm

Hi, I have a spry menu in a site I am completing, but my client wants me to get rid of the hand pointer cursor on the top level links, ie “Business Drivers, EIM Components & About Us” as they do not actually go anywhere. I have tried fiddling with the CSS but am having no luck.
http://sharepointsolutions.co.za/index3.html

Reply

dwcourse October 30, 2011 at 1:27 pm

I don’t usually recommend inline CSS but in this case it makes sense. Add the CSS rule cursor:default to the “dead” inks:

<a class="MenuBarItemSubmenu" style="cursor:default" href="#">Business Drivers</a>

Reply

wayne selmes September 29, 2011 at 1:23 am

hi

i am currently having a conflict between IE and FF.
everything displays fine in IE but in FF the submenu seems to be stacked ontop of each other rather than in a full verticle list. i know its to do with the widths etc but ive plyed with it for nearly 2 days and still having issues. any chance you can see what is causing the issue?

thanks

Reply

dwcourse October 3, 2011 at 3:16 pm

There are other issues on that page and the use of an iFrame in that way isn’t really a good practice. But the issue at hand appear to be the way FF includes the width of the border of a table. Basically you choice is to either reduce the width to the

  • tags in your menu or increase the width of the enclosing table (to 750)
  • Reply

    Bob Gair September 24, 2011 at 8:31 am

    Hi and thanks for being such a great resource for us struggling coders. I have a simple spry menu bar on the site provided. Doesn’t even have drop downs. All is well in Safari and Firefox but as usual Explorer has an issue. I can’t seem to vertically centre the test in the menu boxes in Explorer. Seems like it should be a simple thing. I’m out of ideas and could sure use your help.

    Reply

    dwcourse September 26, 2011 at 4:04 pm

    Vertical centering using CSS is problematic. In spry menus you can adjust the padding-top property in the link tags to adjust the position of the text link.

    Reply

    Korina August 28, 2011 at 12:18 am

    The issue I’m having can be seen on the site in the about tab.

    I’m trying to do a image dropdown but there is padding in between the images that are nested in the , I keep messing with it but I can’t seem to get it to stop. Any guidance?

    Reply

    dwcourse August 29, 2011 at 10:25 am

    Korina discovered the solution without my help and passed it along for others facing the same issue:

    /* added so the images don’t space */
    li img {
    display: block;
    }

    Reply

    brandon August 25, 2011 at 6:10 pm

    Hello,

    I’m having trouble with my dropdown menu. It’s not online btw. I have four categories in my menu but it seems that they are all overlapping and so all I can see is one menu item.. I have no idea what I adjusted incorrectly in the CSS rules but I’m really frustrated … Is there anyway to just reset all the CSS to default. Anytime I try and insert a new spry menu it comes up the same … really really frustrating. any ideas?

    Reply

    dwcourse August 25, 2011 at 9:17 pm

    The default menubar files (including the CSS file) can be found in the following folder (this is for Macs, it should be similar on a PC):

    /Applications/Adobe Dreamweaver CS5.5/Configuration/Shared/Spry/Widgets/MenuBar

    You can make a copy of the css file from here and replace the one you’ve messed up while editing. Be careful not to edit or accidentally move the files in this folder or you’ll break the Spry menubar functionality.

    Reply

    Jenny August 18, 2011 at 3:24 pm

    I am building a website right now and am having difficulty with my spry menu. It is working great for the most part, but I have a gallery menu item that has submenus that is giving me trouble. If I go to any of the submenus (photo gallery, audio gallery, video gallery), I can no longer hover over the Gallery menu item in my spry menu bar to get the submenu to drop down. Since it won’t drop down, I cannot navigate between the different submenus without going to another page on the site in between. How can I fix this?

    Reply

    dwcourse August 18, 2011 at 3:33 pm

    Jenny, in order to help I need to see the page. Can you post a link to it?

    Reply

    Doug August 12, 2011 at 6:03 pm

    Hopefully there is a simple quick fix to my problem.
    I have installed a Spry menu bar using CS5 DW, the menu is no OK after lots of mucking about for IE. My problem is that below the menu bar I have an image inserted in a table cell. The gap between the menu bar (without drop downs) is too much. I would like the image much closer to the bottom of the top line of the menu bar. Do not care if drop down menus appear over the image. I have tried setting borders and margins all over the place, not sure if the issues is with the menu or the table. In either case, problem the same, gap too big.

    Can you help?

    Reply

    dwcourse August 13, 2011 at 12:08 pm

    Re: the site at http://www.carolyngoldberg.com

    Working with tables is going to cause you no end of problems eventually. If you’re serious about creating website, you’re going to need to learn to use divs and CSS styling.

    To address you immediate issue, The list items

  • in a Spry menu are floated left which means they are removed from the flow of the page. So they do not affect the position of object that appear after them (although the contents of those objects will wrap around the floated items). To make the objects after the menu drop below the menu you can insert a line break with the CSS style rule clear:left or clear:both applied like this:


    That’s what’s known as an inline style and it’s generally not the best practice. Ideally you would write a style rule and apply it to the line break. That way you could also add a height to the line break to affect spacing.

  • Reply

    Rajesh Biswas August 17, 2011 at 6:27 am

    Hi,
    There are 2 spry menus in all of my pages in the web site http://demo-debugserver.zymichost.com. The menus and submenus are displayed correctly in the firefox and ie7 but in ie8 the 2nd menu’s submenus are displayed wrongly. There is a huge gap between the menu and submenu.

    Pls help to solve this problem.

    Reply

    dwcourse August 18, 2011 at 3:48 pm

    This won’t solve all your issues but you’ve changed the position property in the ul.MenuBarHorizontal_1 ul style rule from absolute to relative. I don’t know why people change the position properties in the Spry CSS but it’s a popular error. So the first step is to change it back. And, btw, you might want to take a look at The Ten Commandments for Editing Dreamweaver’s Spry Menubars

    Reply

    Dihanna August 8, 2011 at 6:21 pm

    Greetings – I’m just starting with CS5 for our high school pages. I want to incorporate a spry menu (horizontal) … I’ve got it mostly done but how do I use that same menu in all of the other pages?

    Thanks!

    Reply

    dwcourse August 13, 2011 at 12:09 pm

    Sorry for the slow reply. the best thing would probably be to place the menubar in a template and then use the template to build the rest of your pages.

    Reply

    Bo July 27, 2011 at 11:34 am

    so,
    i’m making a website, and the issue is I want my spry bar to move down the page as I scroll down, but thats not happeninf. Would you know how to do that?
    thanks,

    Reply

    dwcourse July 27, 2011 at 11:41 am

    To make an html object that stays in the same position in a browser window you need to use the CSS position:fixed property. Try applying it in the ul.MenuBarHorizontal or ul.MenuBarVertical style rule. If that doesn’t work you might try wrapping the whole menu in a div that is positioned with the position:fixed property. Here’s some info: http://www.w3schools.com/cssref/pr_class_position.asp

    Reply

    1 2 3 4

    Leave a Comment

    { 2 trackbacks }

    Next post:

    Home | Dreamweaver Training | Free Dreamweaver Mini-course | Forum | Make Contact