Skip to main content
Participant
June 29, 2015
Question

making a scroll div inside another div

  • June 29, 2015
  • 2 replies
  • 24543 views

I have a div inside of a div but I want the inner div to scroll when the content gets larger than the div. I used overflow:auto and set the height of the div to 70% and even used a max-height of 70%.

But, as more content is added to the inner div it just gets taller and taller exceeding the 70% and even exceeding the outer div. How do you do this with relative height?

This topic has been closed for replies.

2 replies

HZMD
Participant
October 1, 2016

This might not be the best solution but max-height: 100vh for the scrolling (fixed) div will restrict its height to the height of the view (window)

Nancy OShea
Community Expert
Community Expert
June 29, 2015

Use an explicit height value + overflow:scroll.

#divID {

     height: 100px;

     overflow:scroll;

}

Keep in mind that scrolling divisions are a real pain on mobile devices.  If I had a preference, I wouldn't use them at all.

Nancy O.

Nancy O'Shea— Product User & Community Expert
Participant
June 29, 2015

The problem is I can't specify the height. I need it to be relative.

Nancy OShea
Community Expert
Community Expert
June 29, 2015

That's how you get the scroll bar to appear.  Otherwise the div adjusts normally to content height.

Can I ask why you think you need a scrollbar?

Nancy O.

Nancy O'Shea— Product User & Community Expert