Z-index does not work correctly

Page in question:

http://meyers.ipalaces.org/sitemap/

The first <LI> should be z-index: 2; and should be on top of any other <LI> below. (Meyers)

CSS

 .sitemap #primaryNav > ul > li { float: none; background: #ffffff url('images/L1-left.png') center bottom no-repeat; z-index: 2; position: relative; } 

The idea is that the background color #fff should be lower than t <LI> , so an effect similar to this is created:

http://astuteo.com/slickmap/demo/

if you use firebug at the above link and disconnect position:relative from #primaryNav #home you will see that it looks like mine. I'm not sure how to make him look like them.

+6
html css z-index
source share
4 answers

Positioning and z-index will not be used if the <li> that you are trying to move to the top level actually brings him the entire site map. *

Look at the source of your page side by side with Astuteo code. There are a few places that you REALLY changed the markup:

 Astuteo: <ul id="primaryNav"> /* using natural block tags */ Meyers: <div id="primaryNav"><ul class="level--0"> /* wrapping without need */ Astuteo: <li id="home"><a href....>Home</a></li> /* CLOSED li (immediately) */ *Meyers: <li><a href...>Home</a>...the entire sitemap...</li> /* you wrapped the entire site map inside your first <li> */ 

Your desired solution essentially reflects the source code. Overwriting or copying / pasting at this point is likely to take less time than tracking any remaining errors in modifying the syntax and / or layout strategy.

EDIT : have you tried something as simple as ... removing the background property for the first child at home?

 <ul class="level--1"> <li style="background: none">... 

This would be like in your CSS (to keep CSS outside of your HTML):

 .level--1 li:first-child { background:none; } 
+6
source share

First of all, I would like to note that in your case the "house" is not a source in the site map. Although it may be required that it appear visually in this way, semantically it is not. SlickMap understands this (or maybe they were just lucky), so in its html "home" li is on the same page as the other primary pages. The only thing above other pages is the root, which does not have a page (although most people redirect the root to the "home page").

Secondly, after the parent z-index , if the position: absolute not set for the child, and the position: relative not set to the parent, all children are considered to be initial at a level higher than the parent with respect to the stacking order. This is determined in the CSS 2.1 standard under 9.9.1 Specifying the stack level: the "z-index" property as (focus):

The order in which the rendering tree is drawn on the canvas is described in terms of stacking contexts. Stack contexts may contain additional stacking contexts . The stacking context is atomic from the point of view of its parental stacking context; in other contexts, stacking may not occur between any of its cells.

So, so far, SlickMap has been able to tell you:

The first <LI> should be z-index: 2; and should be on top of any other <LI> below.

In your design, this does not matter, because moving the first li up moves all his children with him. And since the children in your home block start their own stacking context one level above the parent, your β€œhome” li can never be higher than the elements inside it.

Now that is not okay. I looked at your code using SlickMap to understand the differences. As you can see below, there is almost one reasonable option here that will be 100% compatible.

z-index supports negative numbers, but since the stacking context is different from "home" and its siblings, you cannot use this here. However, if for each child element "home" is set to position: absolute , and for "home" li set to position: static (default), you can in some cases use z-index: -1 for these children and make them appear for the parent. But you should also have other variables available (for example, the parent parent background is transparent) And , most importantly, you will need to manually arrange each child. Clearly, this is not a good idea. Not to mention the negatives in z-index is a bug in IE6 / 7.

What you need to do, as SlickMap has done, merge the first ul under li containing "home" with ul.level--0 . This will result in the following hierarchy:

 ul --Home --Meyers --Another Level --M.... --Another Level --etc 

Then you can apply z-index: 2 to "home" li , and you get the result you are looking for. Obviously, changing the structure is likely to require other changes in your styles.

Most likely, some CSS 3 features may help you, but I don’t want to delve into this because I’m not sure about your requirements.

I hope this tutorial in CSS layout strcutres was useful enough for you to make an informed decision about how to move forward with your project. If you have further questions about what I said, just let me know.

+8
source share

Well, it took some time to work, but I think I have it now. I have to say that my sense of Spidey was on top due to the fact that the page does not check .

This is not a z-index problem, since you are using a third-party (and most excellent!) HTML style framework - SlickMap CSS , which should work as advertised.

The problem is not invalid markup, although it must be fixed independently. Namely, that there are no </li> tags in the </li> tags, in utilityNav and duplicate identification attributes in primaryNav there is an invalid <br> .

The problem is that you have implemented additional <ul> levels, and the CSS rules just don't match the right elements. Is this required for any reason? I see that this attempted to be fixed by adding child selectors to your CSS, but the markup is radically different from the expected frame, and therefore the styling of the z index is not correct.

With a minimal <ul> this demo works as expected, since the HTML is correct for CSS SlickMap. Therefore, I will try to remove additional <ul> levels from your markup and imitate the markup on the SlickMap demo page or my violin.

Hope this helps :)

+1
source share

The parent should have a position regarding obtaining the appropriate z-index stacking context. Super obscure, but maybe this will work for you?

Try reading this link to better understand the (super incomprehensible, not yours) method for determining the priority of stacking DOM elements:

https://developer.mozilla.org/En/Understanding_CSS_z-index/The_stacking_context

0
source share

All Articles