I would like an HTML element to show up behind a fixed header element in HTML. (Think dropdown menu under a fixed header.) Problem is, the div element (which is a child of the header element) always displays on top for all permutations of z-index and position I've tried. Please see this fiddle: http://jsfiddle.net/wm3dk82x/4/
Read comments in the jsfiddle code. I've permuted position and z-index, but can't get it to work. HTML and CSS snippets follow:
.header {
background-color: red;
position: fixed; /* must be fixed -- not an option to change this value */
top: 0;
left: 0;
width: 100%;
height: 50px;
text-align: center;
z-index: 5;
}
.divinheader {
background-color: yellow;
position: fixed; /* changed this for every option of position */
padding-top: 50px;
top: 0;
left: 90%;
width: 8%;
height: 20px;
text-align: center;
z-index: 2; /* less than the z-index of parent (2 < 5) */
}
<div class="header">fixed
<div class="divinheader">fixed1</div>
</div>
<div class="content">relative</div>
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>