Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make DIV fixed inside a scrollable DIV

Does anyone now how to make a DIV inside another DIV that is scroll-able fixed, so that no matter how much I scroll by, the DIV always stays in the same place?

Any help would be greatly appreciated.

like image 856
williamtroup Avatar asked Jun 02 '11 14:06

williamtroup


2 Answers

Try this out:

<style type="text/css">
    .scrollable {
        width: 200px;
        height: 200px;
        background: #333;
        overflow: scroll;
    }
    .fixed {
        position: absolute;
        top: 180px;
        width: 200px;
        height: 20px;
        background: #fa2;
    }
</style>
<div class="scrollable">
    im scrollable<br><br>
    im scrollable<br><br>
    im scrollable<br><br>
    im scrollable<br><br>
    im scrollable<br><br>
    im scrollable<br><br>
    <div class="fixed">and I'm fixed</div>
</div>
like image 56
Fredrik Avatar answered Sep 19 '22 10:09

Fredrik


I would recommend absolutely positioning the div over the scrollable div. It wont be in the scrollable div, because it doesn't need to be.

like image 23
zzzzBov Avatar answered Sep 19 '22 10:09

zzzzBov