Here's what I currently have: https://jsfiddle.net/Lt4cmfbo/
CSS
.parent {
position: relative;
float: none;
height: 400px;
width: auto;
background: purple;
overflow: hidden;
display: flex;
flex-direction: column;
}
.childOne {
background: blue;
width: 100%;
height: auto;
overflow-y: auto;
flex-grow: 1;
}
.childTwo {
background: red;
}
.input-chat {
background-color: white;
margin: 5px auto;
border: solid 1px #000;
min-height:10px;
max-height: 100px;
overflow: auto;
width: 95%;
}
HTML
<div class="parent">
<div class="childOne">
<p>
content #1
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
hello
</p>
</div>
<div class="childTwo">
<div class="input-chat" contentEditable="true"></div>
</div>
</div>
Basically, I'm trying to build a chat. Inside of the parent div are two child divs: the top one is scrollable (for displaying messages) and the bottom one is for typing your message to send.
I am using flex boxes to control the height so that both child divs together always equal the parent div height. The bottom child div must expand or shrink based on content (which I have done), while the top child div expands or shrinks based on the height of the bottom child div (which I have also done).
The problem is that I also want the top div to retain its scroll position as its height changes. If I scroll to the bottom of the top child div and see 'hello', I want to still see 'hello' as I am typing up several rows in the bottom div. But instead, the bottom div seems to hide it unless I manually scroll to reveal it.
I hope this was clear enough, but if it's not, I can try to explain it some other way.
I am hoping that my answer is in CSS (or CSS3), but if that's not possible, jquery or pure javascript is fine.