cssscroll

How to make a div scrollable but the rest of the page stay put? (CSS)


I have a div with a list of items that sometimes exceeds the page's height. I want the div to be scrollable while the content on the rest of the page stays put.

I tried adding "overflow-x: scroll" to the div, but that didn't do anything. Thanks!


Solution

  • You need to define a fixed height for that div, i.e. in px or vh as a unit. Or a max-height beyond which it can't grow.

    Plus, for scrolling vertically it has to be "overflow-y: scroll" (or auto), not "overflow-x: scroll" as you wrote in your question.