Custom Drop-Down Menu Colors

Discussion in 'HTML & Website Design' started by rlhanson, Nov 11, 2008.

  1. #1
    A new client posed a challenge to me for an element on his new website we were designing. He wanted a drop-down menu that changed background colors for each menu item to correspond with the background color of each page it linked to. Basically a different color for each menu item.

    I wanted to share the code here for people who don't want to have to take the time to edit the files or don't know how to.

    I have used the script written by Angus at Twin Helix for the drop-down menus in the past and knew this was probably my best option for customization. However, with little experience in actually fully customizing this script - I was a little apprehensive. But, I love a challenge!

    You can see an example of the menu in action here: R.E. Peters Company

    Basically, I removed all the style effects for the background colors in Angus' code, and applied a class to each <li>to achieve the effect.

    style.css:
    
    
    /*MENU*/
    	
    #topnav {
    width:545px;
    padding: 0;
    position: relative; 
    z-index: 999
    }
    
    
    
    .we_are_sub, .we_are_sub a.highlighted:hover, .we_are_sub a:focus, .we_are_sub a:hover {
    	background-image:url(/images/nav_menu/we_are.gif);
    	background-repeat:repeat-y;
    	color:#7e122d;
    	font-weight:bold;
    }
    
    
    .we_do_sub, .we_do_sub a.highlighted:hover, .we_do_sub a:focus, .we_do_sub a:hover {
    	background-image:url(/images/nav_menu/we_do.gif);
    	background-repeat:repeat-y;
    	color:#7e122d;
    	font-weight:bold;
    }
    .we_help_sub, .we_help_sub a.highlighted:hover, .we_help_sub a:focus, .we_help_sub a:hover {
    	background-image:url(/images/nav_menu/we_help.gif);
    	background-repeat:repeat-y;
    	color:#7e122d;
    	font-weight:bold;
    }
    .news_sub, .news_sub a.highlighted:hover, .news_sub a:focus, .news_sub a:hover {
    	background-image:url(/images/nav_menu/news.gif);
    	background-repeat:repeat-y;
    	color:#7e122d;
    	font-weight:bold;
    }
    .contact_sub a:active, .contact_sub a:link {
    	background-image:url(/images/nav_menu/contact.gif);
    	background-repeat:repeat-y;
    	color:#362f2d;
    	
    }
    
    .contact_sub, .contact_sub a.highlighted:hover, .contact_sub a:focus, .contact_sub a:hover {
    	background-image:url(/images/nav_menu/contact.gif);
    	background-repeat:repeat-y;
    	color:#7e122d;
    	font-weight:bold;
    }
    
    
    Code (markup):
    listmenu_h.css
    
    /* HORIZONTAL FREESTYLE MENU LAYOUT */
    
    
    /* All <ul> tags in the menu including the first level */
    .menulist, .menulist  ul {
    	margin: 0;
    	padding: 0;
    	list-style: none;
    	font-weight:300;
    	
    }
    
    /* Submenus (<ul> tags) are hidden and absolutely positioned downwards from their parent */
    .menulist ul {
     display: none;
     position: absolute;
     width: 109px;
    }
    
    /* Second and third etc. level submenus - position across from parent instead */
    .menulist ul ul {
     top: -1px; margin-top: 0;
     left: 105px; 
    }
    
    /*
     All menu items (<li> tags). 'float: left' lines them up horizontally, and they are
     positioned relatively to correctly offset submenus. Also, they have overlapping borders.
    */
    .menulist li {
    	float: left;
    	display: block;
    	position: relative;
    	line-height: 20px;
    	font-family:Arial, Helvetica, sans-serif;
    	font-size: 12px;
    	font-weight: bold;  
    }
    .menulist li ul {
    	top: 25px;
    }
    
    .menulist li ul li ul {
     top: 0px;
    }
    .menulist li ul li a {
    	font-family:Arial, Helvetica, sans-serif;
    	font-size: 11px;
    	font-weight: normal;
    	background: none!important;
    	line-height: normal!important;
    	padding: 5px!important;
     }
    
    /* Items in submenus - override float/border/margin from above, restoring default vertical style */
    .menulist ul li {
     float: none;
     margin: 0;
     
    }
    .menulist ul>li:last-child {
     margin-bottom: 1px; /* Mozilla fix */
    }
    
    /* Links inside the menu */
    .menulist a {
     display: block;
     color: #594519;
     text-decoration: none;
     padding: 0px 0px 0px 0px
     
    }
    
    
    /*Only style submenu indicators within submenus. */
    .menulist a .subind {
     display: none;
    }
    .menulist ul a .subind {
     display: block;
     float: right;
    }
    
    
    /* 'Escaped Comment' hack for horizontal menubar width in IE5/Mac */
    .menulist a {
     float: left;
    }
    .menulist ul a {
     float: none;
    }
    
    .menulist a {
     float: none;
    }
    
    
    
    /*
     HACKS: IE/Win:
     A small height on <li> and <a> tags and floating prevents gaps in menu.
     * html affects <=IE6 and *:first-child+html affects IE7.
     You may want to move these to browser-specific style sheets.
    */
    *:first-child+html .menulist ul li {
     float: left;
     width: 100%;
    }
    
    * html .menulist ul li {
     float: left;
     height: 1%;
    }
    * html .menulist ul a {
     height: 1%;
    }
    /* End Hacks */
    
    Code (markup):
    I'm attaching the style.css and listmenu_h.css for your review - this isn't the complete code you need in order to use the twinhelix menu - make sure you download it from www.twinhelix.com.

    I hope this post helps someone looking for this type of customization!
     

    Attached Files:

    rlhanson, Nov 11, 2008 IP
  2. ForumHog

    ForumHog Active Member

    Messages:
    58
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #2
    Great work. Will use this sooner or later.
     
    ForumHog, Nov 11, 2008 IP