Forum Moderators: not2easy

Message Too Old, No Replies

z-index for Drop down Menu

Disappearing below content

         

wa9578

10:45 am on Jan 14, 2011 (gmt 0)

10+ Year Member



I'm not sure which part of the code you need or if its just a simple thing where you don't need to see it but; I have a couple of drop down menus within my navigation bar.

They drop down fine and redirect where I want/need them to go.

My problem is; within the content section of the website some of the pages either have embedded video's (hosted elsewhere on the net) and some have a photo gallery (created in css).

Upon hovering over the links to get the drop down menu, the drop down menu goes behind the photo gallery and the pictures :S

Is there anyway to stop this from happening? At the moment I can move the photo gallery and the video down but as I get more photo albums online it will leave a large horrible white block of nothingness.

If you need to know what part of the code you need to I'll gladly get it for you

Thanks in advance

wa9578

10:49 am on Jan 14, 2011 (gmt 0)

10+ Year Member



Forgot to mention its also the same for the drop down sub menu's (going behind the content (photo gallery/embedded video's).

Although it goes over the text within the main document fine

webprutser

11:37 pm on Jan 18, 2011 (gmt 0)

10+ Year Member



Have you tried using the z-index in CSS? The z-index property specifies the stack order of an element.
Here is info about it: [w3schools.com...]

Tonight I read the stuff you posted on your dropdown menu. I'm glad yours is working. I'm still struggling with it. I use a bit of Javascript that hides and shows the layer of the submenu. That is working properly, but I have troubles with positioning. I have a vertical menu with images and tried both relative and absolute positioning. None of it works the way I want, but I must admit that I'm no expert when it comes to using CSS positioning properties. I did some reading on it, as well as on the use of div, span, class and id and the general idea is clear to me, but in practice I can't find a way to make my menu work.
Problem with relative positioning is that upon loading the room for the (still hidden) submenu layer is already reserved: result is space between buttons.
Problem with absolute positioning is it works well on one screen dimension only.
How did you get your menu working and could I have a look at it, to check if it what I'm looking for (or are you still working on your site?).
Lot of questions, but I hope you have an answer also now.

wa9578

9:46 am on Jan 19, 2011 (gmt 0)

10+ Year Member



I might have overkilled the z-index but it works now lol quite a simple thing really (once you know what it is), not sure if I can apply it to just the nav bar or all the menu things too lol.

My menu doesn't use Java Script :s its all html and css. I'm not an expert either. This is the first site I've actually done using css and html (the others were like drag and drop stuff, years ago). So its all through what I can read about and the help in here.

I can't give you a link to my site in here as its against the T&C however I think its acceptable to message you the link. It's still a work in progress .

In the mean time ummm this is the html (url's nulled)



<li><a href="#">Team</a>
<ul>

<li><a href="#" class="name">Lucy</a> <a href="#" class="img"><img src="lucycard.jpg alt="Lucy"></a></li>
<li><a href="#" class="name">Hannah</a> <a href="#" class="img"><img src="hannahcard.jpg" alt="Hannah"></a></li>
<li><a href="#" class="name">Phil</a> <a href="#" class="img"><img src="philcard.jpg" alt="Phil"></a></li>
<li><a href="#" class="name">Clare</a> <a href="#" class="img"><img src="clarecard.jpg" alt="Clare"></a></li>
<li><a href="#" class="name">Carly</a> <a href="#" class="img"><img src="carlycard.jpg" alt="Carly"></a></li>
</ul> <!--end inner ul-->
</li> <!-- end team LI -->


and the css;



#siteNavigation ul ul { /**this is the thing I used to hide the drop down menu**/
position:absolute;
visibility:hidden;
top:32px;
}

#siteNavigation ul ul li {/* so the absolute img takes position fromm it */
position: relative;
}

#siteNavigation ul ul a.name {
display: block;
background: #dad;
width: 100px;
height: 28px;
border: 1px solid #000;
border-width: 1px 0;
line-height: 30px
}

#siteNavigation ul ul a.name:hover {
background: #eee;
}

#siteNavigation ul ul a.img {
visibility:hidden; /* hide the image until name is hovered on */
position: absolute;
left: 100px;
top: 0;
background: #eee;
width: 100px;
height: 100px;
}

#siteNavigation ul li:hover ul,
#siteNavigation ul ul li:hover a.img { /* first one shows drop down list, second one shows hidden image link when name is hovered on */
visibility:visible;
}



Although I would love to take credit for it, Majority of it, was Suzy (from this forum).

If you can pm me your weblink too I'll have a look and see if there's anything I can help with. You might find though that if you copy the relevant part of the css and html that people here will be able to give you better help/advice than I can.

SuzyUK

9:47 am on Jan 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think we need to see exactly what elements your menu is going under. Webprutser (Welcome btw!) is right in that z-index should do it.. but there are some elements (iframes and select elements IIRC) that may need some tricks, especially in IE.. "windowed" elements such as iframe and select elements are, or were designed to always "be on top"

anyway in the first instance try adding z-index to the element which activates the drop, i.e. the element with
:hover
- any +value z-index should do, except if you've already got liberal sprinklings of z-index throughout the menu.. in which case try a very high one to test. The element that has a z-index on it must also have position: relative or absolute on it, which shouldn't be a problem as drop menus usually have one or the other ;)

so for example if your drop down menu is activated by hovering over the parent <li> element

ul li {position: relative;}


ul li:hover {
z-index: 1000;
}


ul li ul {
position: absolute: top: 0; left: 0;
display: none;
}

ul li:hover ul {
display: block;
}


that's pseudo code btw, it's not necessarily exactly how you've done it but the theory should be close.

In the above case the child or second level <ul> is hidden until the parent <li> is hovered on - so the <li> is the "parent" element which needs lifting over the top of everything (i.e. brought nearer the viewer), one it's raised the child <ul> should also be on top!

z-index only works on elements that are relative/absolute positioned, and in the above code, there is no need to redeclare a position value on the
li:hover
as it's already on the <li>

SuzyUK

10:00 am on Jan 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



LOL to cross posting :)

OK ignore all of the first bit.. glad it's now working!

adding z-index to an element creates a new "stacking level" - that's not quite right, it can get more complex. however it's easier to think of it like this sometimes. it doesn't actually "raise" the element it's applied to, it creates a new level for descendant elements to stack on

You very rarely need to set a z-index of more than 1 (which actually means +1) but because there are so many tricks, hacks and modules/add-ons out there which use higher values it's often a case of finding the one you need to beat ;)

in a simple scenario, a drop menu should have but one z-index and only on the parent element as described above, because everything thing else descending from that parent will then be in the new "higher" level.

Without it everything on the page appears in the same level and will 'stack' (or paint) as per source order, therefore the later content might well appear over the top of the drop lists. bringing just the inner part (nests/drops) of your menus up into a new level does not affect the stack level of later content therefore the menus (all descendants) should remain nearer the viewer

It can however go pear shaped if later content is positioned too and is z-indexed to an even higher value! or as mentioned if the later content includes iframes or select elements (though that may only be an IE problem?)

wa9578

10:27 am on Jan 19, 2011 (gmt 0)

10+ Year Member



Lol yeah I noticed that too, at least I gave you credit for your coding though :)

I've just kinda cheated atm and whacked z-index in pretty much everywhere. Kind of in a funny mood cos all my work for the last year has gone bye bye so just doing the quick way and will fix it later after I've sorted out encryption issues and grrr rraaarrrr anyone got vodka?

webprutser

11:06 am on Jan 19, 2011 (gmt 0)

10+ Year Member



Thanks, both, for your quick response. That in itself is a good experience.
I will have a close look at it and try it out, later today and will come back to the subject. My site, it's not my own site actually, I'm creating it as a volunteer for a museum that has no budget for it, is not on line, but if I can't get it working I can put it online as a testpage on a site of my own.
Learnt to build websites with tabels and now trying to use more CSS, div and span elements to position elements and that gives me quite some trouble at times. But never mind, I like to learn and when you get some help along the way it is still pleasant (sometimes I went so mad on the whole thing, I wanted to throw my computer out of the window - ran out of wodka :-) ).

SuzyUK

11:26 am on Jan 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Lol yeah I noticed that too, at least I gave you credit for your coding though

I've just kinda cheated atm and whacked z-index in pretty much everywhere. Kind of in a funny mood cos all my work for the last year has gone bye bye so just doing the quick way and will fix it later after I've sorted out encryption issues and grrr rraaarrrr anyone got vodka?


:( No vodka.. it's still earlyish morning here but can feel your pain!

thanks for credit, but no need it's for you to take and learn :) - I didn't realise we were talking about that same menu but the theory should hold good.. your quick fix of z-indexes everywhere should do no harm, it might only ever be an issue if/when you need more positioning.. hope your day gets better soon!

webprutser good luck, and I frequently get the "gonna throw you outta the window!" feeling too.. if your code is still a mixture of tables and CSS-P (positioning) you *might* incur other difficulties as positioning inside tables can be a bit of pain.. however you know where we are should you need any help!

Suzy

wa9578

11:58 am on Jan 19, 2011 (gmt 0)

10+ Year Member



I know it is Suzy, am in the uk too lol.

I get what your saying but credit where credit is due, I wouldn't of got to that stage without your help.

Yeah was about the same drop down menu (I've made it into about 4 now though lol).

I only put the z-index thing in when ever I saw ul and li, they are pretty much going to stay where they are anyway so its all good :)

Only thing I'm left to work out now is how to make it so the last drop down menu goes horizontal rather than vertical when it drops down (I do like to complicate things lol).

Pruster, can you upload it to the test page and then can have a look or put in some code when you've had a go?

I agree with you about people helping and always seems friendly, I joined another forum before I found this to ask a question and tried to help someone, one of the senior members just spoke to us like we were stupid and although my suggestion helped, wasn't the norm. I was like I don't know because I've never been taught or been shown not because I'm a stupid moron. Least here people seem friendly enough although I've mainly spoken to fotiman or suzy lol

webprutser

12:01 am on Jan 20, 2011 (gmt 0)

10+ Year Member



I tested your menu tonight and had some trouble with it. I added <ul> and </ul> at beginning and end, but what about the CSS? You used #siteNavigation, but I can't find anything with #name and #img. I now have a menu showing the buttons of the submenu, but also the names mentioned. How do I get rid of the names and where should I use #img (and #name?) in the CSS? Also would like a button in the main menu (at the place of Team), but the image I added doesn't show up. I replaced your image names with my own images and this is what I used:

<ul>
<li><a href="#" class="name">Team</a><a href="#" class="img"><img src="images/buttons_navigatie_home.jpg" alt="Lucy"></a>

<ul>
<li><a href="#" class="name">Lucy</a> <a href="#" class="img"><img src="images/buttons_navigatie_collectie.jpg" alt="Lucy"></a></li>
<li><a href="#" class="name">Hannah</a> <a href="#" class="img"><img src="images/buttons_navigatie_vrijwilligers.jpg" alt="Hannah"></a></li>
<li><a href="#" class="name">Phil</a> <a href="#" class="img"><img src="images/buttons_navigatie_kinderen.jpg" alt="Phil"></a></li>
<li><a href="#" class="name">Clare</a> <a href="#" class="img"><img src="images/buttons_navigatie_home.jpg" alt="Clare"></a></li>
<li><a href="#" class="name">Carly</a> <a href="#" class="img"><img src="images/buttons_navigatie_activiteiten.jpg" alt="Carly"></a></li>
</ul> <!--end inner ul-->
<!-- end team LI -->
</li>
</ul>

SuzyUK

9:22 pm on Jan 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



webprutser.. you need to wrap the whole thing in a <div id="#siteNavigation"><ul>....</div>
for the CSS in post#3 to work

the name and img classes are in that same CSS, there were more top level choices, other than "Team" in the original menu, but it shouldn't matter for the demo.. what should happen in this code is that you hover over the word team.. and the names appear, then as you hover over a name the corresponding picture appears.

Here's the original thread [webmasterworld.com] so you can see it from the beginning if that's any help.. if you need to, do start a new thread with what you've tried and what you're trying to achieve that way tohers should be able to help out if required :)

webprutser

11:21 pm on Jan 20, 2011 (gmt 0)

10+ Year Member



I'm new here, why would it better to open a new discussion? When you look at recent posts it's on the first page.
I reread the old thread and the first problem I stumble upon is the names ..... how do I get rid of them? I only want my image to be shown.
I added images to the main menu also and have now this html:

<div id= "siteNavigation">
<ul>
<li><a href="#" class="active">Home</a><a href="#" class="img"><img src="images/buttons_navigatie_activiteiten.jpg" alt="Lucy"></a></li>
<li><a href="#">Team</a><a href="#" class="img"><img src="images/buttons_navigatie_contact.jpg" alt="Lucy"></a>
<ul>
<li><a href="#" class="name">Lucy</a> <a href="#" class="img"><img src="images/buttons_navigatie_home.jpg" alt="Lucy"></a></li>
<li><a href="#" class="name">Carly</a> <a href="#" class="img"><img src="images/buttons_navigatie_collectie.jpg" alt="Carly"></a></li>
<li><a href="#" class="name">James</a> <a href="#" class="img"><img src="images/buttons_navigatie_vrijwilligers.jpg" alt="James"></a></li>
</ul> <!--end inner ul-->
</li> <!-- end team LI -->
<li><a href="#">Trainees</a><a href="#" class="img"><img src="images/buttons_navigatie_kinderen.jpg" alt="Lucy"></a></li>
</ul><!-- End main UL -->

</div> <!--siteNavigation end-->

CSS is as on the original thread.

webprutser

12:05 am on Jan 21, 2011 (gmt 0)

10+ Year Member



I'm a bit further. When I remove the names and just use the images things work out fine in the MENU, however the SUBMENU is still the problem. Because the CSS is based on action when there is hovering over the names, I don't see how I can adapt that to my situation and I hope you can help me with this.

SuzyUK

9:25 am on Jan 21, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm new here, why would it better to open a new discussion?


Mainly just forum etiquette ;) this is wa9578's topic & it's about content going behind, also new topics might get a few more responses a bit more specific to your needs as your problem/question has nothing to do with the title of this thread.

but as I already know the story behind the first menu, I'll try

...but I can't find anything with #name and #img.
there is nothing with them as ID's # is the symbol for a CSS ID, however there is for them as classes (.) notation in the CSS

#siteNavigation ul ul a.name {}
#siteNavigation ul ul a.name:hover {}

#siteNavigation ul ul a.img {}
#siteNavigation ul ul li:hover a.img {}



In the menu on the original thread there is three parts (levels) to it: the "trigger" link(main menu item) the "name" part and the "img" part,

....
<li><a href="#">Team</a>
<ul>
<li>
<a href="#" class="name">Lucy</a>
<a href="#" class="img"><img src="lucy.jpg" alt="Lucy"></a>
</li>
...



it was a bit more specialized for wa9578's needs, and will not work if you remove just the name part as it's the bit that needs hovered on to reveal the picture drop, what you need is something a bit more simple..

you would need to remove the CSS for the name class, and swap the img class to where the name class was, you're reducing the menu by one level, in fact you would not need the name/img classes at all! The original was only done this way for wa9578 as he had two <a>nchors in the same <li> element which needed to act differently, in a "usual" scenario there is only one link(or linked img) inside each level <ul><li> of the list so it can be targeted by adding another ul li to the CSS selector

simpler scenario, using images just for you ;)

<div id= "siteNavigation">
<ul>
<li><a href="#" class="active">Home</a></li>
<li><a href="#">Team</a>
<ul>
<li><a href="#"><img src="lucy.jpg" alt="Lucy"></a></li>
<li><a href="#"><img src="hannah.jpg" alt="Hannah"></a></li>
<li><a href="#"><img src="phil.jpg" alt="Phil"></a></li>
<li><a href="#"><img src="phil.jpg" alt="Phil"></a></li>
<li><a href="#"><img src="Carly.jpg" alt="Carly"></a></li>
<li><a href="#"><img src="James.jpg" alt="James"></a></li>
</ul> <!--end inner ul-->
</li> <!-- end team LI -->
<li><a href="#">Trainees</a></li>
</ul><!-- End main UL -->
</div> <!-- //siteNavigation -->


#siteNavigation ul {
width: 250px;
background: #eee; /* grey */
}

#siteNavigation ul li {/* so the second level takes position from it */
position: relative;
}


#siteNavigation ul li a {
display: block;
height: 40px;
}

#siteNavigation ul ul {
visibility:hidden; /* to initially hide the drop down menu */
position:absolute;
top:0;
left: 100px;
width: 150px;
background: #fee; /* pink */
}

#siteNavigation ul li:hover ul { /* reveals second level when hovering on the first */
visibility:visible;
}

#siteNavigation ul ul li {
height: 50px; /* height of second level list element matched to image height */
}

#siteNavigation ul ul a img { /* image dimensions */
display: block;
width: 100px;
height: 50px;
}


try that and play about with some of the sizes and positions to see if that's easier to work with for your needs.. let us know

Suzy

webprutser

12:17 am on Jan 22, 2011 (gmt 0)

10+ Year Member



As to the opening of a new thread: your explanation is clear and makes sense.
I think, however, there is no need for it anymore. At the moment I can hardly believe it, but it seems your code did the job. Based on it step by step I adjusted it to my wishes and it looks like I have a good working menu now. Unbelievable ..... You don't know how much I have tried. Luckily I learnt some stuff in the process, so it's not all waisted time, but I was pretty desparate at times.
I will have a good look at the CSS code you used, I want to understand every bit of it because it caused me so much trouble. Meanwhile I am just very happy and also very thankful. You really helped me a lot with your advise. Thanks so much.

SuzyUK

10:49 am on Jan 22, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're Welcome :) glad it helped your menu and and helped you learn too.

The theory to creating any kind of drop menu is virtually the same whether horizontal or vertical, when trying to get things positioned and sized just comment out the "visibility: hidden" part so you can see the drops, then when everything's where it should be uncomment it to check the "toggle" works.

As long as each level is in a new <ul> the theory for each level is the same, adding more elements to a CSS selector makes it more specific so each "level" just gets another ul and/or li added to it

You *might* come across the "going behind content" problem, but as you already know this should be a case of adding a z-index to the <li> element

Good Luck!

Lorel

4:07 pm on Jan 22, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I read somewhere that videos are designed to float above other content and thus when you set up the code you need to add this to the Object tag:

<PARAM NAME="wmode" VALUE="transparent">

and add this to the Embed tag:

wmode="transparent"

Then the drop down menu will float above the video when z-index is applied.

It works for me.

webprutser

8:23 pm on Jan 22, 2011 (gmt 0)

10+ Year Member



@SuzyUK. I read your explanation and think I understand the CSS code that is written for the various levels of the list.
I am not finished with the menu yet (want a subsubmenu also and highlighting when you hover the buttons, I tried to get a subsubmenu on a certain button, but it's not functioning well), but will take your advise and start a new topic for it.
I am still very happy I have at least a good working menu with submenu's. I can now get the website online. Additional wishes can be implemented at a later stage.