Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS box-shadow hidden (z-index does not fix)

Tags:

css

z-index

I have a box-shadow on my #primaryNav div. Unfortunately, the shadow is being covered/hidden by the background of the following #page element.

I tried to set a z-index of 100 to #primaryNav and a z-index of -100 to #page, but that does not fix my problem.

Any ideas what I'm doing wrong?

like image 236
Tophers Avatar asked Mar 31 '11 19:03

Tophers


People also ask

Why is Z-Index not working CSS?

z-index only works on positioned elements (relative, absolute, fixed, sticky) so if you set a z-index on an element with a static position, it won't work.

What do you do if Z-index doesn't work?

To sum up, most issues with z-index can be solved by following these two guidelines: Check that the elements have their position set and z-index numbers in the correct order. Make sure that you don't have parent elements limiting the z-index level of their children.

Does Z-Index work with fixed?

Note: z-index only works on positioned elements (position: absolute, position: relative, position: fixed, or position: sticky) and flex items (elements that are direct children of display:flex elements).

How do I get rid of Z-Index?

css("z-index", ''); Extract from the documentation : Setting the value of a style property to an empty string — e.g. $('#mydiv'). css('color', '') — removes that property from an element if it has already been directly applied, whether in the HTML style attribute, through jQuery's .


1 Answers

You need to define positioning for #primaryNav. Z-index only affects positioned elements. I just added this in firebug and it fixed:

#primaryNav {   position: relative;  } 

I would avoid using a negative z-index. Simply change z-index of #page to 0.

like image 158
biggles Avatar answered Oct 02 '22 21:10

biggles