there is a div
(namely div_fixed
) which is fixed in position. Another div
namely other_content
is beneath the div_fixed
. The other_content
div has a padding-top
property so that when the page is scrolled only the other_content
is scrolled beneath the fixed div.
The fiddle is here
HTML :
<div class="div_fixed">FIXED</div>
<div class="other_content">
content goes here<br/>
content goes here<br/>
content goes here<br/>
</div>
CSS:
div { color: #fff }
.div_fixed { position: fixed;
width: 100%;
height: 100px;
}
.other_content {
background: #f00;
height: 5000px;
color: #fff;
padding-top: 100px;
margin:0 auto;
}
But I want the non-fixed div to stay upon the fixed div and want the non-fixed div to disappear just beneath its upper edge i.e. position of the non-fixed div's upper edge will remain fixed but it's content will start disappearing on page scroll just the way it happened when it was staying beneath the fixed div.
So i had a little edit in the html ( just 2 breaks) before the non-fixed div :
<div class="div_fixed">FIXED</div>
<br><br/>
<div class="other_content">
content goes here<br/>
content goes here<br/>
content goes here<br/>
</div>
The addition in css is:
.fixed_div{
z-index:-1;
}
.other_content{
width:60%;
z-index:99099900;
}
But the upper edge of the non-fixed div does not stay at the position I want.
How to achieve that ?
EDIT :
suppose I add a background image for the non-fixed div
. Is it possible that part of background image of the fixed div
over which the other div will scroll will have a z-index
higher than that of the non-fixed div
? Will the problem be solved in that way ?
EDIT2
Let use suppose that fixed_div
is the header, other_content
is the content body of a webpage. Let us add a footer div
with id footer
. No scroll should be present in other_content
. other_content
should scroll when the page is scrolled.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…