Overflow-y:scroll should add dynamically on parent div

I want to add scroll when I add my second <p> dybamically on click of button, then on my div with class “box” should add scroll bar.

<div class="box"> 
 <img src="http://placehold.it/450x150" alt="" />  
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Recusandae suscipit, autem magnam ab. Possimus perferendis officiis doloremque impedit quia quos labore optio quas cum incidunt. Blanditiis dicta, sunt numquam quos.</p>  
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Recusandae suscipit, autem magnam ab. Possimus perferendis officiis doloremque impedit quia quos labore optio quas cum incidunt. Blanditiis dicta, sunt numquam quos.</p>
</div>

css:
.box { height: 120px; overflow-y:scroll; padding:5px;}

Thanks.

Hi,

Are you asking for the JS or are you having problems with the CSS?

The css you posted above will add a scrollbar at all times but will be greyed out and only become active if the height is exceeded.

If you use overflow-y:auto instead then the scrollbar will only appear if the height is exceeded rather than being present but greyed out at all times.

Not sure if this is your question though ? :slight_smile:

If you only