CSS Horizontal Menu modified with help notes

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
casidougal
Forum Members
Forum Members
Posts: 98
Joined: Tue Jun 06, 2006 10:08 pm
Location: USA

CSS Horizontal Menu modified with help notes

Post by casidougal »

The CSS menus with CMS MS are awesome tools but they can be a bear to modify for those of us who are not CSS gurus. I've wasted a lot of time messing with modifying the default horizontal CSS menu...I finally sat down and made a modified version with notes. It was difficult for me to get the hover highlight to work in IE 6 and FF 2 but I believe the version below accomplishes this.

The main application I use this for is to create a first menu level with a transparent background so I can style the nav bar area with a gradient background in the main page template.

I've tested this in IE 6 & 7, Opera 9 and FF 2...any comments, corrections or suggestions are welcomed.

----------------------------------------------

/* Horizontal menu for the CMS CSS Menu Module */
/* by Alexander Endresen

Modified by Doug Case http://risingline.com to accomodate a transparent background on primary menu level
EDIT HERE comments added in comments above each element that would be typically edited

Sample coding for using this menu in a CMSMS template:


{menu template='cssmenu.tpl'}

Gotchas:
>Make sure you've got the JavaScript helper loaded or this menu won't work in IE 6
>Apply the Accessibility CSS menu to your templates with this menu or you'll get hierarchical numbers with each menu item

Please contact me with comments, suggestions or corrections at http://risingline.com/contact_general_information.htm

*/


#menu_vert {
  margin-left: 1px;
  margin-right: 1px;
}

/* The wrapper clears the floating elements of the menu */

/* Fix for Opera 8 */
.clearb { clear: both; }

/* EDIT HERE 1 - FROM DOUG - Below styles the dynamically created div id="menuwrapper"
Change settings here to:
>width of nav bar - common widths are 760px, 955px, or 100%
>alignment of all all levels of menu items */
#menuwrapper {
/*  overflow: hidden;  */
background-color: transparent;
width: 760px;
margin-left: auto;
margin-right: auto;
z-index: 500;
text-align: left;
}

/* EDIT HERE 2 - Set the width of the menu elements at second level. Leaving first level flexible. */
#primary-nav li li {
  width: 200px;
}

/* Unless you know what you do, do not touch these positioning elements */
#primary-nav, #primary-nav ul {
  list-style: none;
  margin: 0px;
  padding: 0px;
}
#primary-nav ul {
  position: absolute;
  top: auto;
  display: none;
}
#primary-nav ul ul {
  margin-top: 1px;
  margin-left: -1px;
  left: 100%;
  top: 0px;
}
#primary-nav li {
  margin-left: -1px;
  float: left;
}
#primary-nav li li {
  margin-left: 0px;
  margin-top: -1px;
  float: none;
  position: relative;
}
/* End of positioning elements */

/* Styling the basic apperance of the menu elements
EDIT HERE 3- You can change the text color for all levels of the menu here. To change the sublevel text to a different
color see EDIT 6 */
#primary-nav a {
display: block;
margin: 0px;
padding: 5px 10px;
text-decoration: none;
color: White;
}
/* EDIT HERE 4 - You can edit or remove side bordres on the main nav bar. Font attributes set here affect all levels */
#primary-nav li a {
border-right: 1px solid #C0C0C0;
border-left: 1px solid #C0C0C0;
}
/* EDIT HERE 5 - Edit or remove bordres of the 2nd and 3rd level menu items
If you would like a different font color for submenu text change it here
*/
#primary-nav li li a {
  border: 1px solid #C0C0C0;
}
/* EDIT HERE 6 - I set the background of the main nav bar to transparent so I can
add gradient background pictures in the html.
Obviously, you can also change main nav bar to a different color.
Note: Just changing this background color in the default CSS menu template will also affect
all lower levels of the menu, you must also add the edits in 7 and 8 at the bottom of this sheet. */
#primary-nav li, #primary-nav li.menuparent {
background-color: transparent;
}

/* Styling the basic apperance of the active page elements (shows what page in the menu is being displayed) */

#primary-nav li.menuactive {
  background-color: #C7C7C7;
}

/* Styling the basic apperance of the menuparents - here styled the same on hover (fixes IE bug) */
/* NOTE FROM DOUG - I changed the positioning so it's easier to use other arrow graphics. */
#primary-nav ul li.menuparent,
#primary-nav ul li.menuparent:hover,
#primary-nav ul li.menuparenth {
/* arrow for menuparents */
background-image: url(../ma10.gif);
background-position: 180px center;
background-repeat: no-repeat;
}

/* Styling the apperance of menu items on hover
NOTE from Doug-added "#primary-nav ul li.menuparent:hover," to this section so it works in FF and IE6*/
#primary-nav li:hover,
#primary-nav li.menuh,
#primary-nav li.menuparenth,
#primary-nav ul li.menuparent:hover,
#primary-nav li.menuactiveh {
background-color: #DFBC84;
}

/* The magic - set to work for up to a 3 level menu, but can be increased unlimited */

/*
just add
#primary-nav li:hover ul ul,
#primary-nav li.menuparenth ul ul ul,
for fourth level
*/
#primary-nav ul,
#primary-nav li:hover ul,
#primary-nav li:hover ul ul,
#primary-nav li.menuparenth ul,
#primary-nav li.menuparenth ul ul {
  display: none;
}

/* add
#primary-nav ul ul ul li:hover ul,
#primary-nav ul ul ul li.menuparenth ul,
for fourth level
*/
#primary-nav li:hover ul,
#primary-nav ul li:hover ul,
#primary-nav ul ul li:hover ul,
#primary-nav li.menuparenth ul,
#primary-nav ul li.menuparenth ul,
#primary-nav ul ul li.menuparenth ul {
  display: block;
}

/* IE Hacks */
/* EDIT HERE 7 - You can change the background color of submenu items that ARE NOT parents match with color in edit 8 */
#primary-nav li li {
float: left;
clear: both;
background-color: #5B8AB9;
}
/* Don't change */
#primary-nav li li a {
  height: 1%;
}
/* EDIT HERE 8 - You can change the background color of submenu items that ARE parents (match with color in edit 7) */
#primary-nav ul li.menuparent {
background-color: #5B8AB9;
}
Last edited by casidougal on Wed Jan 10, 2007 4:36 pm, edited 1 time in total.
Post Reply

Return to “Tips and Tricks”