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?
>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:
- You need to add
overflow-yto be set toscroll. - 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>