I have a div position: fixed in the layout, like a sidebar. I was suggested that part of its contents remain fixed to the top (internally), and the rest scrolls if it overflows the bottom of the div.
I looked at this answer , however the solution presented there does not work with position: fixed or position: absolute containers, which is a pain.
I did a JSFiddle demo of my problem here . A large amount of text should ideally scroll, and not overflow at the bottom of the page. The height of the title can vary depending on the content and can be animated.
Sample JSFiddle code:
CSS
div.sidebar { padding: 10px; border: 1px solid #ccc; background: #fff; position: fixed; top: 10px; left: 10px; bottom: 10px; width: 280px; } div#fixed { background: #76a7dc; padding-bottom: 10px; color: #fff; } div#scrollable { overlow-y: scroll; }
HTML:
<div class="sidebar"> <div id="fixed"> Fixed content here, can be of varying height using jQuery $.animate() </div> <div id="scrollable"> Potentially long content </div> </div>β
Without a fixed header, I can simply add overflow-y: scroll to div.sidebar , and I can happily scroll through all the content if it overflows the bottom of the container. However, I am having problems with having a fixed, variable-height header at the top of the sidebar and having any content under this scroll if it is too long to fit into the container.
div.sidebar should remain position: fixed , and I would really like to do it without any hacks, and also make it as convenient as possible. I tried to do different things, but none of them work, and I'm not sure where from here.
How can I make the div inside the position: fixed container scroll only in the Y direction when the content overflows the containing div, with a fixed variable header of undefined height? I would love to stay away from JS, but if I have to use it, I will.
css overflow
Bojangles Apr 14 2018-12-14T00: 00Z
source share