javascript - How to fix a div inside another element which contains scrollbars? -
i have div of height:x; width:y; overflow:auto; displays content of article. naturally, content extends beyond constraints of div, scrollbar appear let me read through content.
the div contains 'close' link position: absolute; top: 20px; right: 20px; displays 'x' close div (using jquery & animations). problem is, scroll through article, 'x' scrolls it. want 'x' remain in same position rather move content.
i've tried changing position value 'fixed' fixes body of page, not div. how can overcome without positioning div outside main content?
<div class="box1"> <a data-type="close">x</a> <div class="inner"> //content// </div> </div>
make wrapper div same size inner scrolling div , add position:relative; position close button absolutely within wrapper div , increase z-index above inner div.
the code (based on html):
.box1 { position:relative; height:100px; width:200px; } .inner { width:200px; height:100px; background:#f2f2f2; overflow:auto; } { top:0; right:0; position:absolute; }
Comments
Post a Comment