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

Display ReactJS Components Within a Scrollable List with height:auto

How can I render the same component inside a map, without overlapping, but one below another

Here’s what i mean:

return (
    <div className='app'>
        {[0, 1, 2, 3].map(element => {
            return(<MyComponent props = {element}/>)
        })}
    </div>
)

How can I display that component in a scrollable list, considering that its height is auto?

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

>Solution :

You are Describing the Default Behavior Already

How can I display that component in a scrollable list, considering that its height is auto? [emphasis mine]

With height:auto;, the behavior you describe happens already:

.item {
  height:300px;
  border: 1px solid black;
}
<div class='app'>
    <div id="1" class="item"></div>
    <div id="2" class="item"></div>
    <div id="3" class="item"></div>
</div>

But if you wanted a Limited Scroll

You need two things:

  1. You need to add overflow-y to be set to scroll.
  2. You need to set the height to how much of a scrollbar you want.
.app {
  height: 40px;
  overflow-y: scroll;
}

.item {
  height:30px;
  border: 1px solid black;
}
<div class='app'>
    <div id="1" class="item"></div>
    <div id="2" class="item"></div>
    <div id="3" class="item"></div>
</div>
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