1

The problem is simple:

http://jsfiddle.net/boblauer/wfLGG/

In the left example, I have the whole thing scrolling, which works fine because I can set the scrolling div's height to 100%. In the right example, it doesn't work, because I don't know what my scrolling div's height should be, because it's sharing that space with another element. If I set it to 100%, it overflows from its container, causing the 2nd scrollbar that you see in the example.

I know I can use javascript to set the .scroll-container's height to (container height - height of the header), but is there a pure css solution to this problem? I hate having to use javascript for this, especially because when the window resizes, I have to recalculate the size of the scrolling div.

Edit: Sorry, I wasn't very clear. What I want is for the header to remain static at the top, while the list itself is scrollable.

3
  • Yes, that's exactly the behavior I'm looking for, except with that solution the bottom of the list is cut off. Commented Oct 18, 2012 at 16:23
  • Looks like the problem remains. If you look at the scroll bar on the right, you can see the bottom arrow is cut off. Which makes sense, since that div's height is set to 100%, but the header above it is pushing it down some. Commented Oct 18, 2012 at 16:30
  • Ug, you're right, I completely missed that. Commented Oct 18, 2012 at 16:32

2 Answers 2

2

I think this is maybe helpful

.scroll-container {
    overflow: auto; 
    padding-top:20px;    
}

#ex2 span{
position:absolute;
    background:white;
}

jsFiddle

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I may actually end up going this route since I know my header's height will be static. If the header height was unknown at design time, your solution wouldn't work without setting the padding-top to the header's height with javascript.
2

Set overflow: y-scroll; on #ex2 and it will behave as #ex1.

#ex1, #ex2 {
    float: left;
    height: 100%; 
    width: 45%;
    border: 1px solid black;   
    overflow: auto;   
}

#ex2 { overflow: y-scroll; }

Demo

4 Comments

I just edited the original question, but what I want is for the header to stay static while the list scrolls.
Is it important that the header is inside the scroller?
No, in fact I don't want the header to be inside the scroller, but it does need to stay inside of #ex2. So I want the header to stay where it's at, at the top, while the rest of the list scrolls.
I think it's probably as close to a pure css solution as there is tbh. It's not perfect, because the content is actually extending past the container. You can see this easier if you put a red border around the .wrapper element, as I did here: jsfiddle.net/boblauer/MdgTs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.