I'm trying to use z-index to layer a button and a div. The button appears behind the div, while according to z-index it should be in front of it. Here is the style elements associated with the button & div as captured by Firebug:
Note that the button has a z-index of 2, the div has a z-index of 1, and both are position:relative.
Full HTML is in this pastebin.
z-index is a relative, not an absolute value.
An object with z-index 10 billion will not appear on top of all elements on the page, only on top of other elements in the same stacking context
http://css-discuss.incutio.com/wiki/Overlapping_And_ZIndex
http://tjkdesign.com/articles/z-index/teach_yourself_how_elements_stack.asp
In the CSS hierarchy you posted, it looks like the button and div are contained in different elements (#note18 and #note19), so you'll have to make sure that those elements aren't creating different stacking contexts which will make any z-indexes for elements inside them irrelevant to each other.
Related
I am currently trying to create a landing page for a photoshop layout. I am quite new to HTML and CSS and I am having trouble solving this. My drop-down menu lists are getting covered by the content. I think it might be about positioning... Thanks
I will attach a picture and I will also share my code if needed...
Dropdown menu getting covered by content (positioning) IMAGE
As previously stated you can use z-index to determine how elements are rendered on top of each other. Elements with an higher z-index are on top of elements with a lower z-index.
According to the MDN docs:
The z-index CSS property specifies the z-order of a positioned element and its descendants. When elements overlap, z-order determines which one covers the other. An element with a larger z-index generally covers an element with a lower one.
Just but z-index:999; on your dropdown.
Objects with higher z-index number will go above those with lower numbers.
Add the CSS attribute z-index: 999; to your dropdown's CSS. Not necessarily should it be 999, but just that 999 is the maximum one can use in z-index.
The property of z-index is that a division with a higher z-index will be displayed above a division with a lower number in the z-index, therefore allowing you to decide the hierarchy of the appearance of different divisions.
To know more, visit https://www.w3schools.com/cssref/pr_pos_z-index.asp
If z-index is not solved, you can check nav container and if you found overflow-y you can comment that line.
I was trying to answer this question: How to make a colorful gradient glow around your input-box?
My problem and question is why does the rainbowBg div appear over the input and not behind it? I have tried positioning the input absolute, setting z-indexes, nothing worked.
<div class="rainbowWrap">
<div class="rainbowBg"></div>
<input class="rainbow" type="text"/>
</div>
Try typing in the input. You can only focus it if you click between the input border and the rainbowBg div. I have only tested in Chrome.
http://jsfiddle.net/b03acbdu/4/
z-index only works when you define position. Add "position: relative" to your rainbow class.
Just give the div a negative z-index. You can even remove z-index from the input then.
.rainbowBg {
z-index: -1;
}
http://jsfiddle.net/b03acbdu/6/
It goes behind the input because z-index is ingored for non-positioned elements and so givern a fixed value of 0. From MDN:
When no z-index property is specified, elements are rendered on the default rendering layer 0 (zero).
In terms of z-index being relative to parent or the whole document, MDN again has a useful article describing The Stacking Context. The children of .rainbowWrap are put into their own stacking context, so because .rainbowBg is a child of it, it will always be "on top of" it's prent's background. Or as the article puts it better:
An easy way to figure out the rendering order of stacked elements along the Z axis is to think of it as a "version number" of sorts, where child elements are minor version numbers underneath their parent's major version numbers.
I am having a z-index issue. I have a couple of div that sit on top of each other, within them div there is some content which shows on mouseover. This content is currently being displayed behind the parent div.
The parent div have a z-index: 2 as they need to be displayed above there own parent.
<div class="activity-display"><!--parent div z-index: 2-->
Running<!--This is displayed on hover underneath its parent div, but gets hidden underneath the below activity-display-->
</div>
<div class="activity-display">
Running
</div>
I have tried adding a higher z-index to the anchor and this doesn't solve the issue
Any help would be greatly appreciated
When using the z-index property elements must be positioned. Change the a tag to position:absolute.
You should at least give the elements you want to work with z-index a relative position, because z-index doesn't works on a static position. So really any other than the default position works.
You also don't need to rearrange children or parents elements, because children elements will always be over the parent. In other words, a child element will always have a z-index + 1 relative to the parent.
Please make a fiddle, so that we can help.
Also, some points to keep in mind, z-index works for elements position absolute.
I have a webpage that I need to modify, the background, which is currently absolute positioned with z-index to push it back, needs to stay put when scrolling, i need to change it to fixed, yet doing so seems to break z-index and push the content below it vertically. Any ideas?
edit:
OK I managed to get it to work in FF, but IE is still broken...
Maybe look at the rules below for how elements are stacked.
The Stacking order and stacking context rules below are from this link
Stacking Order within a Stacking Context
The order of elements:
The stacking context’s root element (the <html> element is the only stacking context by default, but any element can be a root element for a stacking context, see rules below)
You cannot put a child element behind a root stacking context element
Positioned elements (and their children) with negative z-index values (higher values are stacked in front of lower values; elements with the same value are stacked according to appearance in the HTML)
Non-positioned elements (ordered by appearance in the HTML)
Positioned elements (and their children) with a z-index value of auto (ordered by appearance in the HTML)
Positioned elements (and their children) with positive z-index values (higher values are stacked in front of lower values; elements with the same value are stacked according to appearance in the HTML)
When a Stacking Context is Formed
When an element is the root element of a document (the <html> element)
When an element has a position value other than static and a z-index value other than auto
When an element has an opacity value less than 1
Several newer CSS properties also create stacking contexts. These include: transforms, filters, css-regions, paged media, and possibly others. See https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
As a general rule, it seems that if a CSS property requires rendering in an offscreen context, it must create a new stacking context.
Made a quick test. In its simplest form z-index doesn't break when using position: fixed;.
Perhaps you can put the background that is already there in a wrapper for the whole page and use the gradient background on the body instead.
Depending on the gradient, you can also try using a css3 gradient on the background of the body (or simply multiple backgrounds...) and use css3pie to make it work in IE.
On this website: http://fa-aft6157.org/ , when viewed in IE8, when you hover the mouse over the links on the left they appear at the top of the page. How can this be fixed in the HTML code?
Whenever you position an element absolutely with css, the element is positioned relative to the closest parent that has position defined.
I think your problem has to do with the fact that all of your menu DIVs are direct children of BODY. You may have better luck placing your menu DIVs inside a parent DIV that has position defined.