z-index not working with overflow to overlap and scrollbar - html

I got the following issue:
I'm trying to display a few <div.content> with content in it. Limited in size to a <div.holder> as parent with overflow set, so that you can scroll down to see all <div.content>. The <div.content> are overlapping the <div.holder> for styling purpose. And everything is wrapped in a <div.container>.
But the <div.content> won't display over the <div.holder> element with z-index or anything. It's rendered inside the <div.holder> element, without scrollbar it's rendered outside, like i want.
How can i get the Scrollbar and that the <div.content> will overlap its parent <div.holder>?
Here's the Fiddle for the issue. Thank you.
EDIT:
Trying to accomplish this:
For this styling purpose:
Is this even possible? I'm not bound to just use HTML&CSS, just need that thing start working.

Z-index will only work on elements with position. So its not doing anything to .foo
http://www.w3schools.com/cssref/pr_pos_z-index.asp

Related

Absolute positioned element is invisible even when setting high z-index

Code pen showcasing problem.
https://s.codepen.io/NoMan2000/debug/rdPEYJ/xnrabdnqJadA
I apologize for the rather gnarly HTML, but this is output from a next.js project so the bloated mess is part and parcel of that.
Anyway, the problem can be seen in the element #header-menu-buttonList. The idea is pretty simple, a menu that goes underneath the main grid element. But for whatever reason, it just sits there on the page.
You can pick it up in the debug tools and see that it has a width and a height. Messing with its z-index doesn't make the object visible, only removing the position: absolute makes it visible on the page, but that opens up a whole host of other issues.
So, anyone know:
1.) Why the heck it's doing that?
2.) How to either fix it or work around it?
Thanks for the rubber-ducking. :)
So the issue is that the parent element is positioned absolutely, and the child element is positioned absolutely. I'm not up to snuff on all my CSS rules, but this appears to keep it in the DOM but not render it visible.
The solution is to set the child #header-menu-buttonList to position: static and the parent #header-menu-button to position:absolute.

How to make a div of dynamic height and scroll when it goes out of viewport?

I know I can give a {max-height} and {overflow: auto}. But I want the max-height to be dynamic and not fixed.
Lets say that we have 2 divs on a page, if div#1 is hidden the max-height of div#2 should increase so that it occupies the maximum area before scrolling, and scrolls only when it goes out of the viewport.
Sample jsbin: http://jsbin.com/voworuveqe/edit?html,css,js,output
Edit
Please CSS solutions only. No JS. Thank you!
you should use a method like this one:
function('click',{
if(hide==true)
hide =false;
Document.getElementById(/*element*/).style="{max-height:"/*someheight*/"}"
else
hide =true
Document.getElementById(/*element*/).style="{max-height:"/*someotherheight*/"}"});
I've written up a quick example using hover instead of hidden and height instead of max-height but it should work fairly similar if you change it.
https://jsfiddle.net/6pdu6tvz/4/
The only restriction is that the element that you want to change must appear after the element you want to hide.
You cannot change elements before on hover as answered here: How to style the parent element when hovering a child element?. I would recommend using Javascript if you can (although you specified in your question not to).

Why won't this parent div respect the height (with padding) of its children?

I want to create a button/link that is centered in the content area of a webpage. Because it's a button, and not just a link, I'm adding some padding and background colour to it.
The link is centered horizontally, but the padding seems to expand outside the line-height of the parent element, causing it to overlap with previous/next elements. See: http://fths.convoke.info/what-can-i-do/
I tried creating a fiddle, but wasn't seeing the same issue: http://jsfiddle.net/convoke/g9wu6ws9/
So what am I missing? Conversely, is there a better way to center a link like this? I don't like using margin: auto because it requires you specify the width. Ideally the width would be dynamic, so if the text on the button was longer or shorter, it would remain centered.
In this case, the answer I needed came from user #CBroe in the comments of my original question. He suggested using display:inline-block and that worked like a charm.
Still unsure as to why I was getting different results on the fiddle vs the actual website...

Position Fixed Header goes behind text when Position Relative element is added

So I know there are a plethora of questions about position fixed/relative/absolute in relation with z-index, but I still couldn't figure out my question using those.
Essentially I have a header that is fixed. It works perfectly fine, everything goes behind it when scrolling down the page.
I recently wanted to add links to div ids, but in order to account for the header, I had to add the following code where link is the parent element, and then linkTo is the class of something with an ID that we actually link to. This functionality works completely, providing the correct offset so that the header is above the div we want.
.link {position: relative;}
.linkTo {position: absolute; top: -80px;}
The problem with this, is that for some reason now my div is behind everything on the page. I can still see it but the text and images are in front.
I've tried adding z-index to my header (of like 9999) but it isn't working. I don't understand why adding position relative would mess up the order of how things are displayed.
I'd like to provide an example, but my code is rather large. If this isn't enough I can try to make a jfiddle later.
Add position: relative; z-index:9999 to the parent element it will keep this element stick inside the menu.
As Ganesh said, adding position: relative to the parent element of the header was the starting step. After that adding z-index to the same parent element fixed the problem completely.
Check for a lower z-index on a parent element, it appears to override the z-index of children.
I've run into z-index issues in the past with drop down menus and jquery UI tabs. I thought it had something to do with the stacking effects created us rules like opacity or transition, but for me the problem was a parent element having a lower z-index than a child element.

Targeted horizontal overflow

Is there a way to target html elements that I don't want to affect the width of the page?
In other words, those elements wouldn't trigger the horizontal scrollbar, if they were to leave the browser box.
You could use the CSS overflow: hidden to keep them from affecting your layout.
You can use overflow:hidden on the elements you don't want the scrollbar on.
You can also use overflow-x:hidden or overflow-y:hidden Reference
Checking other sites structures, the solution seems to be pretty simple:
Wrapping everything in a relative positioned container(with overflow:hidden) lets the container grow with the contents of the page, while not letting the elements show out of it's borders.
Example:
http://jsfiddle.net/LnNQJ/1/