Home > Net >  How to make scrollbar appear on modal when content is large, and disapper when content is small?
How to make scrollbar appear on modal when content is large, and disapper when content is small?

Time:01-04

Introduction

I have a React project in which I have a Modal component. Here is how it looks (the content of the modal does not matter):

enter image description here

Here is what is looks like when I set overflow-y to scroll, and the content is small (as you can see, there is a tiny inset on the right side of the modal):

enter image description here

Here is what it looks like when I set overflow-y to scroll, but with a larger amount of content (as you can see, it is scrollable):

enter image description here

Question

How do I get rid of the little inset displayed in the second picture, while still setting overflow-y to scroll. In other words, how can I configure it so that when the content is small, there is no scrollbar and when the content is large, there is a scrollbar?

CodePudding user response:

You can set overflow-y to auto

This will make the scrollbar to appear only when the content is very long and the scrollbar will be needed, or else the scrollbar will not be there.

  •  Tags:  
  • Related