I have a parent div with two child divs (heading and body), I want to set the position of the heading fixed at the top, and only the body should scroll.
HTML
<div class="box"> <div class="header">Header</div> <div class="body">Body</div>
CSS
.box { height: 300px; border: 1px solid #333; overflow: auto; } .header { position: absolute; width: 100%; height: 100px; background: #ccc; } .body { height: 300px; background: #999; margin-top: 101px; }
I found that the div title overlaps the scrollbar of the parent div. I cannot set the parent position of the div as relative, because I want the title position to be fixed. I canβt set the title position as βfixedβ because this content may be somewhere in the middle of the page.
How can I avoid an absolute positioned child element that does not overlap the parent scroll bar?
Find jsfiddle: http://jsfiddle.net/T43eV/1/
source share