Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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):

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading