Reputation: 6488
html:
<div class="div_fixed"></div>
<div class="other_content">
content goes here
</div>
css:
.div_fixed{
position:fixed;
height:40px;
}
.other_content{
height:200px;
}
The div_fixed
will remain fixed at the top position of the page.
But as the page scrolls up, the content of the div other_content
will vanish just at the lower edge of the div div_fixed
.
In the case of scrolling down the invisible content of other_content
will begin to be visible from the lower edge of the div_fixed
How to achieve that ?
EDIT: no scroll bar should appear for any div
Upvotes: 0
Views: 436
Reputation: 3087
I've taken your HTML/CSS and added a bit on a jsFiddle - I think in order to achieve the effect you're looking for, you just need to make your content actually tall enough to be scrollable. At 200px high and one line of text, nothing is going to scroll.
So I made your other_content
div taller, and then added a top: 0
to your .div_fixed
selector, to keep it stuck to the top of the screen, and a margin-top: 40px
to the .other_content
div in order to have it start below the floating div.
If you want it to be a navbar-type thing, you can of course add a width: 100%
to the .div_fixed
.
All of this should transfer into a container div (with position: relative
) fairly easily as well if you want, although you may have to re-position the fixed div.
Upvotes: 0