scriptygoddess

03 May, 2008

Suckerfish Dropdown navigation going behind content

Posted by: Jennifer In: CSS|Javascript

Awhile back, I had a project where I created a nice clean (X)HTML page including navigation using UL and LI tags. A few months later the client decided they wanted to add a dropdown menu to the navigation. No problem, I thought. We just add the embedded lists to the navigation – style it with CSS – and use the Suckerfish dropdown menu technique. Easy Peasy.

Except when I implemented it, the drop down menus were showing up BEHIND the rest of the content instead of "above/over it".

There was a lot of other things going on in the page, I have a simple example that demonstrates the issue.

I'm sure it makes sense somehow, if I had a better grasp of what "position: relative" does to the document – beyond that "position: relative" allows items INSIDE a relatively positioned block to be absolutely positioned WITHIN it (which is why I had done that). The side effect though is that it does that crazy thing with the menu.

Oh the HOURS and HOURS to figure that out…. /sigh.

Here is the same page – with just that one line (position: relative) removed.

I've now seen this problem crop up a few times. In one case, I was working with a design that I had not originally created and even though there were no "position: relative" in any of the css files – the only way to get the menu to be ABOVE the content was to explicitly declare "position: static" inside the div tag itself. (Even just declaring it in the css wouldn't fix it – somewhere else it must have still been getting overridden)

While I'm at the point where I can't even imagine designing a page using a table based layout anymore, I still get hit with some CSS sticking points that I just don't get. So if you have more insight on this feel free to elaborate in the comments. I'm just so glad I was able to get the menu working!

15 Responses to "Suckerfish Dropdown navigation going behind content"

1 | lucas

May 4th, 2008 at 9:15 pm

Avatar

try setting the div's z-index to a value of like 30 or something really high….

2 | Emily

May 6th, 2008 at 3:45 am

Avatar

z-index: 10 on #nav li ul will pop the menu forward.

Are you using Firebug (the firefox add-on)? It make debugging the css so much easier.

3 | Emily

May 6th, 2008 at 5:21 am

Avatar

More of an explanation now that I've had some coffee and a shower:

z-index: 10 on #nav li ul will pop the menu forward.

Absolute positioning takes the element out of the flow of the document. So elements that come after are stacked on top of the absolutely positioned one.

Z-index gives a weight to elements and the higher the number the more to the top of the stack the element is.

All elements have a default z-index of 1 (it's actually the z-index of the parent element but unless it is set somewhere, it is 1). Z-index can only be specified on elements that have position specified.

Are you using Firebug (the firefox add-on)? It makes debugging the css so much easier.

4 | Jennifer

May 6th, 2008 at 7:33 am

Avatar

I know in the case most recently – where I had to specifically add "position: static" to the tag itself – that adding z-index to the embeded UL didn't make a difference. (This is why I hate working with other people's code/layout) – but good to know for the future – if I *have to* make the next div position: relative – that I should start working with z-index to fix the navigation issue…

5 | Jennifer

May 6th, 2008 at 9:50 am

Avatar

And now I'm also hearing from some people that one of the pages where that navigation lives is plauged with a "sticky hover" problem. I'm still working on resolving it – but going to save this link here for (my) future reference.

http://www.satzansatz.de/cssd/pseudocss.html#stickyhover

6 | lucas

May 17th, 2008 at 8:16 pm

Avatar

i generaly do a div{position: relative;} at the very begining of my css files so that if i have any absolutely positioned divs they don't screw up and be positioned absolutely in the page….. it also takes care of z-indexing….

7 | Kerry

July 16th, 2008 at 7:05 am

Avatar

I was having the same problem, hours and hours spent trying to fix it, to the point I was almost in tears!

By removing the "position: relative;" from the CSS under the "#content-wrap" absolutley worked a treat and now my drop-down suckerfish menu works sits above the main content.

So simple, and yet so very very effective.

THANK YOU SO SO VERY MUCH

Total Star! :-)

8 | Jennifer

July 16th, 2008 at 7:48 am

Avatar

For some reason the second example has stopped working entirely. :/ Not sure why. At some point I'll get around to cycling back to this issue to fix the examples.

9 | Steve

August 20th, 2008 at 1:46 am

Avatar

Just learned yesterday that in IE, if the dropdowns are in one section that is position:relative, and the area where they are to display is in another position:relative section, that the dropdowns display behind the content in the second section.

I was able to resolve this by combining both sections into one so the whole thing was in one position:relative . After doing so it works fine.

My original attempt worked fine in FF. It was IE (as usual) that was the problem. This resolved the IE problem.

10 | Gareth

March 22nd, 2009 at 3:18 pm

Avatar

Can somebody help me please?

I'm having the same IE7 problems with a suckerfish menu. The dropdowns work fine in Firefox, but in IE7, they go 'behind' the graphic underneath the menu. Annoying, as most of our visitors still use IE.

This is an extract from my template.css file.

/** @MENU **/

/** @SUCKERFISH **/

/* Mainlevel */
ul.menu-suckerfish {
z-index: 1;
float: left;
border-right: 1px solid #404040;
margin: 0;
background: none;
padding: 0;
list-style: none;
}

ul.menu-suckerfish li {
float: left;
display: inline;
background: none;
margin: 0;
padding: 0;
}

ul.menu-suckerfish a:link,
ul.menu-suckerfish a:visited {
display: block;
border-right: 1px solid #000000;
border-left: 1px solid #404040;
margin: 0;
padding: 3px 1.5em;
color: #ffffff;
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-weight: bold;
text-decoration: none;
}

ul.menu-suckerfish a:hover {
background-color: #404040;
}

ul.menu-suckerfish li.active a {
background-color: #404040;
}

/* Sublevel */
ul.menu-suckerfish ul {
position: absolute;
left: -999em;
z-index: 2;
margin: 0;
padding: 0;
list-style: none;
}

/* Other containers */
ul.menu-suckerfish ul ul {
margin: -26px 0 0 184px;
z-index: 3;
}

/* Items */
ul.menu-suckerfish ul li {
position: relative;
width: 185px;
margin: 0;
background: none;
padding: 0;
}

ul.menu-suckerfish ul a:link,
ul.menu-suckerfish ul a:visited {
display: block;
border-top: 1px solid #366999;
border-right: none;
border-bottom: 1px solid #162c40;
border-left: 1px solid #162c40;
background: #284d73 none;
color: #cfdbe5;
padding: 4px 10px;
font-size: 0.9em;
font-weight: normal;
text-decoration: none;
height: 1%;
}

ul.menu-suckerfish ul a:hover,
ul.menu-suckerfish ul li.parent a:hover,
ul.menu-suckerfish ul li.parent li.parent a:hover {
border-top: 1px solid #1f3d59;
background-color: #1f3d59;
color: #ffffff;
}

/* Active */
ul.menu-suckerfish ul li.active a,
ul.menu-suckerfish ul li.active li.active a,
ul.menu-suckerfish ul li.active li.active li.active a {
font-weight: bold;
color: #ffffff;
}

/* Clear active */
ul.menu-suckerfish ul li.active li a,
ul.menu-suckerfish ul li.active li.active li a {
font-weight: normal;
color: #cfdbe5;
}

/* Children expanded */
ul.menu-suckerfish ul li.parent a,
ul.menu-suckerfish ul li.parent li.parent a {
background: #284d73 url("../images/suckerfish-expand.png") no-repeat 95% center;
padding-right: 10px;
}

/* Clear children expanded */
ul.menu-suckerfish ul li.parent li a,
ul.menu-suckerfish ul li.parent li.parent li a {
background-image: none;
}

/* Rollover actions */
ul.menu-suckerfish li:hover ul,
ul.menu-suckerfish li.hover ul,
ul.menu-suckerfish li:hover ul li:hover ul,
ul.menu-suckerfish li.hover ul li.hover ul,
ul.menu-suckerfish li:hover ul li:hover ul li:hover ul,
ul.menu-suckerfish li.hover ul li.hover ul li.hover ul {
left: auto;
}

ul.menu-suckerfish li:hover ul ul,
ul.menu-suckerfish li.hover ul ul,
ul.menu-suckerfish li:hover ul li:hover ul ul,
ul.menu-suckerfish li.hover ul li.hover ul ul,
ul.menu-suckerfish li:hover ul li:hover ul li:hover ul ul,
ul.menu-suckerfish li.hover ul li.hover ul li.hover ul ul {
left: -999em;
}

ul.menu-suckerfish,
ul.menu-suckerfish li li {
clear: left;
}

Can anyone suggest what I need to amend please?

Thanks

11 | Jennifer

November 8th, 2009 at 6:44 pm

Avatar

note for myself :) I had this happen again where position: relative had nothing to do with it. The suckerfish menu was going behind a youtube video, and adding wmode="transparent" to the embed tag fixed it. 😀 (Was only seeing the problem in IE)

12 | Erica

December 21st, 2009 at 12:41 pm

Avatar

I'm having a similar problem with a weebly site right now. I'm customizing the site for my friend to use for her letterpress business. Flyout menus work perfectly in everything except IE – where the menus on the Invitations –> Wedding, etc. pages go BEHIND the pictobrowser. I tried putting in z-indexes for all the elements, tried putting in the wmode="transparent" in the embed tags – nothing is working. I think I'm losing hair… or maybe just pulling it out… here is the site:

blushdesignstudio.weebly.com

If anyone could give me some help, I would SO appreciate it – I just don't even know what to do at this point, short of scrapping the menus altogether, which is a shame since they work in everything except IE. (I hate IE more than anything… I've been having IE issues with other site designs all weekend… ugh…)

13 | stephanie

January 20th, 2010 at 7:20 pm

Avatar

Thanks soooo much! I made a nav on my CSS and it was falling behind the content area and the "z-index" really helped!
For anyone else having this problem, here is some more info:
http://www.w3schools.com/Css/pr_pos_z-index.asp

THANKS!!

14 | Tony

February 22nd, 2011 at 9:08 am

Avatar

Wow you have no idea how much that helped. I have been trying for days to figure it out and the static directly on tag fixed it. Thanks you!!!!!

15 | Jessica

March 2nd, 2011 at 8:16 am

Avatar

Thank you. You just saved me 10 hours of confusion :)

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements