Nested lists and z-index - html

I'm building a navigation menu for a website and the menu has submenus. When the submenu slides down, it needs to lie behind the main navigation. I've tried using z-index but it won't work. Since the submenu is a child of the LI, is it not able to lie behind?
The code is a bit verbose due to the image sprite, so I'll link to a pastie:
http://pastie.org/1100075
And here's some images to support my explanation.
Desired outcome: http://imgur.com/WeU5T.png
Current outcome: http://imgur.com/0ZC4v.png

Move the li.home a link out side of ul.nav, and put it inside of an absolutely positioned block element with a z-index > 0.

Related

Strange behaviour with floated elements which appear to have relative positioning

I am going through a book on responsive web design in which the author builds the webpage at this address: http://responsivewebdesign.com/robot/
Since the webpage is responsive, if you view it at a browser screen width greater than 1025px, you can see that the h1 element with class logo sits on top of the unordered list with classes nav and nav-bar (the ul being the navigation bar).
See the below link to the screenshot taken of the webpage in Chrome Developer Tools for an example of what I mean by this.
ul with nav and nav-primary classes highlighted in Chrome Developer Tools:
As you can see in the above image, that unordered list which composes the navigation menu bar sits underneath the h1 logo element. You can go to the website, open it in your browser and see this for yourself.
Now with the background information given here's my question.
How is it that h1 element with logo class is able to sit on top of ul with nav and nav-primary classes?
As far as my understanding goes, you would normally have to have the unordered list with position set to absolute in order to do this (both are floated left), but upon inspection in Chrome Developer Tools both of the above mentioned elements have position set to relative.
I can not replicate this in the way that the creator has created it. What am I missing or not understanding here?
The logo element in particular is positioned relative in order to be given a z-index, if the logo is given a z-index higher than that of the navbar then it would seem to be layered on top of it.
After playing around with the html and css I discovered that the h1 element with class logo is floated to the left in the css and the div element with class nav-bar alongside it did not have a float on it and hence had 100% of the width of the containing element and was therefore able to overlap the area taken up by the h1 element with class logo.

Margin from one element obscuring hover state of another

I have a Flexbox based nav menu with a logo aligned in the horizontal center of inline links. Every pen or fiddle I tried making of this doesn't replicate what I'm getting for some reason, but you can go to this Flexbox test here which is almost exactly what I'm working from and if you go into an inspector and add an anchor to the main logo image you'll see what I mean.
The way this is set up is the third link has a left margin of auto applied to fill in the extra gap for the logo to fit in. The logo area is separate from the nav menu in the markup but flexbox layout puts them all in line with each other (at lower breakpoints the nav menu moves down).
Now this all works fine and good until you decide to make the logo a clickable link. When you do that, the margin from that third link obscures the hover state of the logo.
Here's a visual example:
So if you tried hovering over the logo where the margin area intersects it, you would not be able to click the logo, nor get a pointer cursor or any hover states (like a background change). Outside of the margin while over the logo, it works fine, but to a user, they're going to think something strange is going on. This happens if the logo is an img (as it is in the original example) or an SVG (as I'm trying to use).
Trying to see if there's a way around this without having to completely nuke my Flexbox layout. My markup is very similar to what is being used in that example. I've tried toying with a higher z-index for the logo compared to the nav, which didn't work. Giving the nav a negative z-index lets you click the logo but then you can't click the nav items.
You can add a relative position to the logo and then play around with the z-index to make the logo the first element.
.logo {
position: relative;
z-index: 1;
}

Pure css popup submenu not displaying properly

I've created menu drop down menu in pure css,
here, parent div have position:relative and the menu popup have position:absolute,
when the menu hovered the submenu will appear as display:block,
but here, hovering sarees (first menu) the popup menu appears perfectly, but hovering the last menu webmenus, the popup appers at wrong position (different position). The images uploaded below
I want to make the same position with all submenu popups like sarees's submenu popup have.
is there any css hack for this .. ?
Images :
I want this position for all menus
The menu Displaying at wrong position
I noticed that you are using position: relative to the menus, including the drop down menus. That is the why you are having this issue. You set the menu as absolute and it is understood as relatively to its respective parent. If you remove the position: relative it will set absolute position relatively to the page.
Update:
See a Fiddle HERE
and compare to this another Fiddle HERE
Did you see the difference?
Sorry if my english is bad
Remove position:relative; to each .menuTemplate1 li
That way the menu will open always on the left side, as your image shows.

Drop down menu hidden behind

I have created a dropdown menu but the problem I'm having is that when I hover over the top navigation menu, the drop-down menu items are hidden behind the slider and content.
I looked online and trying to figure out the problem but cannot fixes.
Does anyone can hel me? Please if is possible explain really well.
Thanks in advance,
Helen
This is most likely down to the css z-index of the various elements on the page. Higher z-index values will position stuff on top of lower z-index values (providing they have a positioning value). However, you have to bear in mind that child elements cannot gain a higher z-index than their parent element, or at least you can assign the z-index to any value but they will always remain within the parent element at the parent elements z-index value. Most likely the slider on your page has a higher z-index than your header/menu bar.
Also, make sure you have position:relative, position:absolute or position:fixed or the z-index will be ignored.
If you're using a HTML list e.g. <ul> try adding a higher z-index to your list to bring it over everything else.
.dropdown li {
z-index:999;
position:relative;
}
I had a similar problem when working with my drop down menu and it showing up behind the slider. The slider z-index ranged from 1-5 so I made the z-index of the drop down much larger and it now displayed correctly.

CSS only dropdown menu with gap between li:hover and child ul not working in IE

I have a basic css only dropdown menu that works great in Chrome and Firefox but not so well in IE9. The issue is that the design I am implementing has a slight gap between the horizontal row of parent items and their respective child lists of sub navigation items.
I'm displaying the sub-menus on hover of the parent li. The sub-menus appear fine in all browsers.
The problem occurs when I attempt to move the cursor across the small (about 10px) gap between the parent li and the submenu unordered list. The cursor does not actually leave the parent li as the gap is made by applying a larger height to the li (and a smaller height to its child anchor element) so I do not understand why IE is acting like li:hover is no longer happening once my cursor is no longer on the child link.
If I move the cursor really fast across the gap I can actually make it to the sub menu and use it fine but this is no good for usability reasons.
I'm definitely missing something really obvious here!!
To view the problem please visit http://beta.pancreaticcanceraction.org/
Add 'preview2012' to the end of that URL to access the site (I didn't want to put the whole link down in case it gets crawled).
Thanks in advance for any help!
If you set the background of your LI (LI.parent) to be red, you will see that in IE, it doesn't matter how much extra height you give it, it's only as high as the containing NAV element.
I've been mucking around with the IE9 dev tool, to try and get it to sit on top and "outside" the NAV container, but no luck yet. I thought I would post to help get you on the right direction.
EDIT:
if you put a "position: relative" on your UL.menu element, it fixes the issue.
Hope that helps!