Reputation: 981
I am creating a chat application in Angular and I am trying to set up the UI for it. I need to create a div that will be housing the chat messages and as more messages fill the div I do not want the div to expand but just stay the same size and show a scroll bar. This div should be 100% the size of the parent div. As you click the button to add data the div grows. Even if I set a height in px or percent format the div still grows.
Upvotes: 1
Views: 875
Reputation: 1107
The page you link won't load but here are the basics to make a scrollable element:
HTML / JS Structure
div
div
(this will be the "scroll wrapper")insertAdjacentHtml
or whatever works for your specific situation)This order of steps in particular will work well for a scenario where the contents are dynamically changing.
CSS
For the outer container
width
and set height: auto
border-radius
if you want circular edgesoverflow: hidden
to keep the scroll wrapper's corners from popping outpadding
For the inner container
position: relative
overflow-y: auto
and overflow-x: hidden
so that you can scroll up and down, but not side to sidewidth: 100%
and set fixed values for max-height
and min-height
. (max-height
decides when things will start to overflow ie. make a scroll bar)
max-height
and min-height
to be less than the outer container's fixed width
+ any padding
, etc. it may have.Upvotes: 1