Next.js Discord

Discord Forum

CSS and Layouting: How to make a DIV scrollable vertically while the window does not scroll ... 😦

Unanswered
Cuvier’s Dwarf Caiman posted this in #help-forum
Open in Discord
Cuvier’s Dwarf CaimanOP
Any suggestions?

4 Replies

Three-toed Woodpecker
Use overflow property
This is obviously a very very over exagerated example but here you go 🙂

export default function Component() {
  return (
    <div className="flex items-center justify-center min-h-screen bg-gray-100">
      <div className="w-[100px] h-[100px] bg-white rounded-lg shadow-md overflow-hidden">
        <div className="w-full h-full overflow-y-auto p-2">
          <h2 className="text-sm font-bold mb-2">Scrollable Content</h2>
          <p className="text-xs">
            This is a small box with scrollable content. You can add more text or elements here, should start scrolling when its more than can fit
          </p>
          <ul className="list-disc list-inside text-xs mt-2">
            <li>Item 1</li>
            <li>Item 2</li>
            <li>Item 3</li>
            <li>Item 4</li>
            <li>Item 5</li>
            <li>Item 6</li>
            <li>Item 7</li>
            <li>Item 8</li>
            <li>Item 9</li>
            <li>Item 10</li>
          </ul>
        </div>
      </div>
    </div>
  )
}
@Cuvier’s Dwarf Caiman Any suggestions?
give a fixed or max-height to your DIV and overflow-y-auto as well
Classic css, theres many ways to do it 😄