Solved

jquery dropdown menu help

Posted on 2013-01-08
2
431 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
Dean OBrien earned 250 total points
ID: 38758306
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
ID: 38760945
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CSS auto-height of empty div 3 70
problems with widget background image 9 35
Displaying Text in Columns in HTML 3 32
return to same tab when data is posted 6 31
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

739 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