magic with z-index - css

Okay, I have typical menu (ul>li>a). The mission is to draw background <div> (shadow, gradient etc) into an <li> element (ul>li>.shadow-bg-white)
(for example, the div is green bordered. all other borders are just for better visibility of problem)
http://jsfiddle.net/voilalal/P57yE/embedded/result/ or http://jsfiddle.net/voilalal/P57yE/6/
(for example, the div is bordered with green color)
If I hover over the items from left to right, everything is okay. However, if I hover over the items from right to left, items on the left side do not react to the :hover pseudo-class.
Every block has the CSS position property assigned, so z-index should work well, I hope.
At least, .shadow-bg-white z-index seems to be placed higher than the a item.
What solution can you recommend?

Benjam was on the general right track I think. I don't know your ultimate purpose, so the solution may not work in your case, but there is no other solution. The li you are hovering on must be set lower than the others so the div in it does not overlap them. Adding this:
#header-menu ul li:hover {
z-index: 498; /* one lower than your set z-index for li */
}
See here: http://jsfiddle.net/P57yE/8/.
The reason it worked going left is that by default when items are at the same z-index the one coming later in the source order is given precedence, so as you move right you move down in your html source order and the hover is picked up on the new element with the same z-index. But when you move left, you are going up in the html source order so the one you were hovering on had precedence and the hover remains.

They don't react because they are being covered by the div, therefore the div is stealing the hover from anything below it.
If the div does not need to be covering all of the LIs, you might want to place it below the LIs with z-index. But I'm not sure exactly what you're trying to do here, so I'm not sure if that solution will work for you.

Related

Box shadow does not cover div

It is my first qustion :)
Box shadow does not cover drop-down ul. See the screenshot, please - http://i31.fastpic.ru/big/2012/0202/7d/83a6dfa12f24ace82a3df52b6fe0587d.png. I am trying to solve it for a several hours but no result :(
It is strange I have gave z-index to parent element 500 and to the drop-down ul 1 but shadow is still under drop-down ul not over it.
Here is the link: http://layot.prestatrend.com/
Hope someone will help me, thanks.
That's an issue regarding the stacking context.
The point is you can't place the block lower than the closest parent with non-static position and positive z-index. So, you have the z-index:100 on the #categories_block_top .tree li, so you can't place the ul under it.
To fix that (one of the ways) you can remove this z-index, then add position:relative;z-index:1; to the #wrapper and then add the negative z-index like z-index:-1; to an ul. Doing so you'll put it on the same level as the #wrapper, so it would be over the content after it, but under the box-shadow of the #subheader.
Prepend an inner (or inset) shadow on the first li element of the dropdown list.
I guess because the element will always be inside the main menu, the shadow won't work or appear above the sub list.

IE7 z-index with an unordered list

The following example is a very simplified version of my top navigation.
http://jsfiddle.net/AEqxT/
If you look in most browsers, you should see two green list items next to eachother, with a blue box or 'badge' sitting on top, bridging the gap between the two. In IE7 however, the blue box always falls below the second li. I've tried all manner of fixes to this. Setting a higher z-index to the parent ul didn't change anything, and if I use position: relative; on the 'badge', it loses its width and height.
Is there an obvious fix to this that I am missing?
You'll probably struggle with your badge in with the LI, take it out of the list and you should be ok, with a bit of messing with position:
http://jsfiddle.net/AEqxT/2/
If you absolutely have to have it in with the LI, then you'll probably have to have some JS to make this work
This is a reported IE7 bug.
You could fix it with the JS solution posted to this question, or you could manually set different z-indexes to all <li> element, ordered from high to low values:
http://jsfiddle.net/AEqxT/3/

A depth (z-index) nightmare

The best way to illustrate this question is with...a Fiddle! Before you visit the fiddle, notice there is text behind the grayest element, which is on top of a light gray element that has a border.
There is a main wrapping div (root), and two wrapping divs inside (wrap1 and wrap2). The problem here is that I need the content of wrap2 (highlight) to be behind the content of wrap1 (text), but in front of the background of the root.
This, however, must not change:
The HTML, the elements and wraps should be left untouched. Excluding the order of wrap1 and wrap2 inside root.
The highlight div must keep the absolute positioning.
Styling highlight with background-color is not an option, the existence of highlight is a must.
PS: the italics reference the id's of <div>s in the fiddle example, for whomever was too lazy to visit it.
I was able to display the text in front of the highlight by adding a z-index to text. (Adding the z-index to wrap1 also works.) The trick is to remember that z-index doesn't apply to statically-positioned elements, so you need to give the same div position: relative.
#text {
position: relative;
z-index: 1000;
}
(Large z-index because I've been bitten by IE not respecting low values in the past. May or may not still be an issue. ;-)
z-index can be difficult to grasp. I think somebody already answered your question, but if you want to learn more how they work, this is a pretty comprehensive guide:
http://www.onextrapixel.com/2009/05/29/an-indepth-coverage-on-css-layers-z-index-relative-and-absolute-positioning/
And also, here is a link where you can try out different z-index and how they are affected by different position properties (the main reason for difficulty)
http://tjkdesign.com/articles/z-index/teach_yourself_how_elements_stack.asp
#wrap1{position:absolute;z-index:2;}

Absolutely positioned links shifting to unexpected position on click (a:active)

I have a couple links on this page (http://tuscaroratackle.com) that are ending up at unexpected positions in their :active state. The links are absolutely positioned, so I'm guessing the issue is partly due to that. But I can't figure out what rules are getting applied on :active to make them shift down and to the left so far. I do have one rule that makes them "depress" a bit on active ( a:active {position:relative; top:1px;} ) but can't quite figure out why they are shifting so badly.
The links in question are these:
it's the "See Rods" link that appears on hover. If you click you'll see the awkward resulting positioning.
Also for those that don't know (I recently found out) you can inspect the :active state in firefug. Just use the drop down arrow on the style tab to toggle those styles on.
From description of position:absolute:
Generates an absolutely positioned element, positioned relative to the first parent element that has a position other than static.
And, as you noted, you have position:relative; defined for a:active. Now, therefore, in <a><span></span></a> combination position of span is counted relative to position of a, not to position of .hp-promo-item.
As for solution, if you need to move a down 1 pixel on :active, maybe margin-top will work better. But wait, you already have margin-top:1px for .promo-content .icon. Well, maybe margin-top:2px !important; then. I don't really understand the aim to suggest more.
PS Thanks for telling about :active helper in firebug, pretty useful!

CSS float causing background image to appear incorrectly

I'm using a background image to add a custom bullet to list items in my content. In the content there are also images floated left. When an image and a list item are next to each other, the bullet appears where it would do if the image wasn't there, but the text wraps around the image.
Here is an example:
http://golf2.test.textmatters.com/content/greenkeepers/turfgrass/turfgrass_speci/cool_season_gra
is there a way to make the bullet appear where is should (i.e. next to the text)?
In Firebug / Firefox (you'll have to check other browsers) I solved your problem adding a:
li {
overflow:hidden;
}
Don't know why exactly, but that magical line solves lots of problems around floated stuff :-)
Edit: Solution if you can change the html slightly
If you have any control over the html, you could perhaps use paragraph tags instead of list items:
p.list_item {
background: transparent url(/++resource++stylesheets/images/bullet.gif) no-repeat scroll left 0.45em;
padding-left: 11px;
}
However, that would kind of change the semantic meaning of the list items...
This is an old topic... but thought I would add how I usually do this in case someone stumbles in here via a search...
If I have an image on the left, and plan to have graphic bulleted unordered list (UL) to the right of it, I place the image statement inside DIV tags, and add a float:left style to that DIV.
Then, I wrap my UL tags inside a DIV, and give that DIV a float:left style as well, causing it to appear to the right of the first DIV.
If I have additional text that I would like to resume UNDER my UL, then I give the second DIV a width that equals the total width of the page/column minus the graphic width - basically, to account for all of the space to the right of the image. That will force continuing text to flow directly under the UL DIV, and if the UL is shorter than the graphic, the text will flow to the right of the graphic and then under the graphic as expected.
If the UL extends lower than the graphic, then the text will just start under the image, as expected.
If you want the text to simply start UNDER the left graphic regardless of the height of the UL, then you could just apply a clear:both style to the ensuing , i.e.
In general this approach works so long as the UL isn't too much taller than the left image, because obviously in this scenario, the list itself isn't going to wrap under the image, leaving whitespace - so to make a long list look right may require some purposeful image sizing, or stacking a couple of images in the first DIV, or whatever other solution you might have.
If you really want to get whacky, I've had a few times where I've used the two DIV method described above, but setting the first DIV to position:relative, and placing the second DIV containing the UL INSIDE the first, with a position:absolute and of course top:??px and right:??px, set of course to absolutely position my UL to the right of the image. It takes the right kind of layout to use this method, obviously...
OK that's all I had to say, hope this makes sense & good luck to whomever!
Try wrapping your list items in a <p> tag, and then give that tag a left margin.
Why do you have div.fig width set to 0 in the html?
<div class="fig" style="width: 0px;"><img src="/images/43_Fescue.jpg" float="0"/></div>
Remove that and the list will float around the image.
Well, it's not the best fix from a stylistic point of view, but floating the images right avoids this problem. Thanks for everyones suggestions
If you want the whole ul to NOT float under the image try adding overflow:hidden to the ul

Resources