Solved

jquery dropdown menu help

Posted on 2013-01-08
2
416 Views
Last Modified: 2013-02-22
I'm having 2 issues...

1. Please take a look at the screen shot and you will see that I have a border that is offset. Just trying to get it to line up.

2. Is there a way to offset the end menu (menu6) because it will be wider so right now it is hanging off the page.

JS Fiddle

http://jsfiddle.net/DURB7/

INLINE JS

$(document).ready(function() {

      // Create dropdown menus
      $('.nav_menu .dropmenu').css('display','block');
      $('.nav_menu > ul').dropmenu({
            effect : 'slide',
            speed : 250,
            timeout : 0,
            nbsp : false
      });
      
      // Indicate items with sub-menu
      $('li').has('ul').find('> a').addClass('indicator');
      
});


JS FILE

JS File

CSS

.nav_menu {height: 40px; background-color: #FFF; font-family: 'proxima-nova', Arial, Helvetica, sans-serif; color: #930; font-weight:lighter; position: relative; z-index: 1; width: 968px;}

/* drop menu */
.nav_menu .dropmenu { margin: 0; padding: 0; /* displays after menu load */ }

/* topitems */

.nav_menu ul.dropmenu li {text-transform:uppercase; text-decoration:none; font-size:12px; color:#FFFFFF; line-height: 12px; margin-right: 5px;}
.nav_menu ul.dropmenu a.toplevel { height: auto; margin: 7px 20px 7px 10px; padding: 0px 0px 0px 0px; color: #fff; text-decoration: none; }

.nav_menu ul.dropmenu {display:table-row-group;} 

.nav_menu ul.dropmenu li.menu1 {width: 156px; background-color:#598527; height: 40px; display:table-cell; border-right: 5px solid #FFF;}
.nav_menu ul.dropmenu li:hover.menu1 {background-color: #598527; border-bottom: solid 5px #598527;}
.nav_menu ul.dropmenu .sub-menu1 {position: absolute; display:block; left: 50px; background-color:#598527; width: 156px; border-bottom: 5px solid #FFF; border-left: 5px solid #FFF; border-right: 5px solid #FFF;}

.nav_menu ul.dropmenu li.menu2 {width: 156px; background-color:#007476; height: 40px; border-bottom: solid 5px #FFF;}
.nav_menu ul.dropmenu li:hover.menu2 {background-color: #007476; border-bottom: solid 5px #007476;}
.nav_menu ul.dropmenu .sub-menu2 {background-color:#007476; width: 478px; border-bottom: 5px solid #FFF; border-left: 5px solid #FFF; border-right: 5px solid #FFF;}

.nav_menu ul.dropmenu li.menu3 {width: 156px; background-color:#404041; height: 40px; border-bottom: solid 5px #FFF;}
.nav_menu ul.dropmenu li:hover.menu3 {background-color: #404041; border-bottom: solid 5px #404041;}
.nav_menu ul.dropmenu .sub-menu3 {background-color:#000000; width: 156px;}

.nav_menu ul.dropmenu li.menu4 {width: 156px; background-color:#404041; height: 40px; border-bottom: solid 5px #FFF;}
.nav_menu ul.dropmenu li:hover.menu4 {background-color: #404041; border-bottom: solid 5px #404041;}
.nav_menu ul.dropmenu .sub-menu4 {background-color:#000000; width: 156px;}

.nav_menu ul.dropmenu li.menu5 {width: 156px; background-color:#404041; height: 40px; border-bottom: solid 5px #FFF;}
.nav_menu ul.dropmenu li:hover.menu5 {background-color: #404041; border-bottom: solid 5px #404041;}
.nav_menu ul.dropmenu .sub-menu5 {background-color:#000000; width: 156px;}

.nav_menu ul.dropmenu li.menu6 {width: 156px; background-color:#404041; height: 40px; border-bottom: solid 5px #FFF;}
.nav_menu ul.dropmenu li:hover.menu6 {background-color: #404041; border-bottom: solid 5px #404041;}
.nav_menu ul.dropmenu .sub-menu6 {background-color:#000000; width: 478px; margin-right: 50px;}

.divider-space {width:5px; background-color:#FFF; background-image:url(../images/nav/white-bg.png);}


/* subitems */

.nav_menu ul.dropmenu li ul li a.sublevel { color: #fff; width: 141px; padding: 5px 5px 5px 10px; margin: 0;}
.nav_menu ul.dropmenu li ul li a.sublevel.hover { color: #fff; background-color: #333; }
.nav_menu ul.dropmenu li ul li a.sublevel.selected { color: #f7ad0b; }
.nav_menu ul.dropmenu li ul li a.sublevel.hover.selected {  }

Open in new window


Menu...

<nav class="nav_menu">
    <ul class="dropmenu">
        <li class="menu1"><a href="#">Menu1</a>
            <ul class="sub-menu1">
                <li><a href="#">Sub Link 1-1</a></li>
                <li><a href="#">Sub Link 1-1</a></li>
                <li><a href="#">Sub Link 1-1</a></li>
            </ul>
        </li>
        <li class="menu2"><a href="#">Menu2</a>
            <ul class="sub-menu2">
                <li><a href="#">Sub Link 1-1</a></li>
                <li><a href="#">Sub Link 1-1</a></li>
                <li><a href="#">Sub Link 1-1</a></li>
            </ul>
        </li>
        <li class="divider-space">&nbsp;</li>
        <li class="menu3"><a href="#">Menu3</a>
            <ul class="sub-menu3">
                <li><a href="#">Sub Link 1-1</a></li>
                <li><a href="#">Sub Link 1-1</a></li>
                <li><a href="#">Sub Link 1-1</a></li>
            </ul>
        </li>
        <li class="divider-space">&nbsp;</li>
        <li class="menu4"><a href="#">Menu4</a>
            <ul class="sub-menu4" >
                <li><a href="#">Sub Link 1-1</a></li>
                <li><a href="#">Sub Link 1-1</a></li>
                <li><a href="#">Sub Link 1-1</a></li>
            </ul>
        </li>
        <li class="divider-space">&nbsp;</li>
        <li class="menu5"><a href="#">Menu5</a>
            <ul class="sub-menu5">
                <li><a href="#">Sub Link 1-1</a></li>
                <li><a href="#">Sub Link 1-1</a></li>
                <li><a href="#">Sub Link 1-1</a></li>
            </ul>
        </li>
        <li class="divider-space">&nbsp;</li>
        <li class="menu6"><a href="#">Menu6</a>
            <ul class="sub-menu6">
                <li><a href="#">Sub Link 1-1</a></li>
                <li><a href="#">Sub Link 1-1</a></li>
                <li><a href="#">Sub Link 1-1</a></li>
            </ul>
        </li>
    </ul>
</nav>

<div style="clear:both;"></div>

Open in new window

1.png
0
Comment
Question by:brihol44
2 Comments
 
LVL 12

Accepted Solution

by:
Dean OBrien earned 250 total points
Comment Utility
somewhere in the jquery menu code, it is setting left:0px for the submenu. This is overwriting the css you have (i.e. where you have left:50px - this is doing nothing). You need to find and change that to left:-5px.

Or remove the 5px border from the main menu.

Similarly, for the last menu item, set it to left:clear;right:0; this should hang from right side then and not go over page.

easynow
0
 
LVL 16

Assisted Solution

by:HagayMandel
HagayMandel earned 250 total points
Comment Utility
The problem is with your borders:
You give the secondary ul tags wide white borders (not in all of them), and this creates the offset for sub menus 1 & 2.
More important, this is cause by too much copy & paste instead of trying to create some uniformity in the css.
Try the following:
create a class for the primary list items (li), that includes all the common css rules that apply for each item such as: width, line height, position etc.
 and apply it to all primary list items.
create a class for the secondary list items that includes all the common css rules that apply for each item such as: width, line height, position etc.
and apply it to all secondary list items.
Add the custom css rule for each of the list items (I believe that after applying all the mutual / common css rules. only background-color will be left.
By such an approach, you'll prevent errors like those extra borders, and different widths (in response to your second question), and validate that all components have the same style.
And finally, this method, is much more flexible and versatile than the inline styling that you use.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now