Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

making a scroll div inside another div

Explorer ,
Jun 29, 2015 Jun 29, 2015

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?

23.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 29, 2015 Jun 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 & Moderator
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 29, 2015 Jun 29, 2015

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 29, 2015 Jun 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 & Moderator
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 30, 2015 Jun 30, 2015

Because the containing div is fixed and so everything that extends beyond the viewport is unaccessable.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2015 Jun 30, 2015

If the containing div is the restriction, the you need to place the scrollbar(s) on it and not on the inside container by using overflow:scroll;

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 30, 2015 Jun 30, 2015

I tried that but that just scrolls the background (the fixed containing div) while the foreground div stays in place (clipped off screen). I need the foreground to scroll and not the background.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2015 Jun 30, 2015

Do you have the child container set to position:fixed or position:absolute (it shouldn't be)?

That's all I can think of that would cause the child container's content to stay put when you scroll after using Ben's suggestion on the parent container.

As a side note, you may also want to set background-attachment:fixed for your parent container to make sure any background image stays put when scrolling happens.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2015 Jun 30, 2015

Because the containing div is fixed...

Bad idea.

Try something else like this:

jQuery Smooth Scrolling with Fixed Layout

Nancy O.

Nancy O'Shea— Product User, Community Expert & Moderator
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 30, 2016 Sep 30, 2016
LATEST

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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines