Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

jquery dropdown menu help

Posted on 2013-01-08
2
Medium Priority
?
438 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 1000 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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
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 style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
Suggested Courses

782 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