Reputation: 1940
I have been struggling with this problem for over 2 hours, Is there a way to make a div fixed while it is inside a bigger div. When I scroll I want to keep the right part not scrolling.
So my question is, is there a way to do this without jquery?
Thanks
Upvotes: 1
Views: 4717
Reputation: 72261
This fiddle demonstrates the following solution:
HTML
<div class="wrapper">
<div class="scroller></div>
<div class="fixed"></div>
</div>
CSS (example of key parts)
.wrapper {
position: relative;
height: 40px;
overflow: hidden;
}
.scroller {
padding-right: 200px;
height: 100%;
overflow: auto;
}
.fixed {
position: absolute;
top: 0;
right: 15px;
bottom: 0;
width: 160px; /* .scroller padding minus the right offset to accomodate scroll bar and minus any real separation between it and the scroller */
}
Upvotes: 0
Reputation: 219920
You have to position the inner div absolute
ly:
.outerDiv {
position: relative;
/* give it some height */
}
.contentDiv {
height: 100%;
overflow: auto;
}
.innerDiv {
position: absolute;
right: 0;
left: 50%;
top: 0; bottom: 0;
}
Here's the fiddle: http://jsfiddle.net/wSxss/
Adjust the positioning values according to your needs.
Upvotes: 6