Run the following snippet:
html {
height: 100%;
}
body {
margin: 0;
height: 100%;
}
.chatPanel {
display: flex;
flex-direction: column;
background-color: #e0e0e0;
height: 100%;
}
.chatListContainer {
background-color: #d9faff;
position: relative;
}
.inputBar {
background-color: #d9ffdb;
padding: 5px;
}
.chatMessage {
background-color: #ffc1c1;
margin: 10px;
padding: 10px;
font-size: 18px;
}
.floatingIndicator {
position: absolute;
left: 0;
bottom: 0;
background-color: purple;
}
.chatList {
}
<!DOCTYPE html>
<html lang="en">
<body>
<div class="chatPanel">
<div class="chatListContainer">
<div class="chatList">
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
</div>
<div class="floatingIndicator">Text here</div>
</div>
<div class="inputBar">
InputBar
</div>
</div>
</body>
</html>
Note that everything scrolls. This is the problem: I want chatListContainer
and inputBar
to both be contained inside chatPanel
so that inputBar
stays fixed at the bottom.
At first sight, this could be easily achieved by adding overflow: auto
to chatListContainer
, like this:
html {
height: 100%;
}
body {
margin: 0;
height: 100%;
}
.chatPanel {
display: flex;
flex-direction: column;
background-color: #e0e0e0;
height: 100%;
}
.chatListContainer {
background-color: #d9faff;
position: relative;
overflow: auto;
}
.inputBar {
background-color: #d9ffdb;
padding: 5px;
}
.chatMessage {
background-color: #ffc1c1;
margin: 10px;
padding: 10px;
font-size: 18px;
}
.floatingIndicator {
position: absolute;
left: 0;
bottom: 0;
background-color: purple;
}
.chatList {
}
<!DOCTYPE html>
<html lang="en">
<body>
<div class="chatPanel">
<div class="chatListContainer">
<div class="chatList">
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
<div class="chatMessage">Chat message</div>
</div>
<div class="floatingIndicator">Text here</div>
</div>
<div class="inputBar">
InputBar
</div>
</div>
</body>
</html>
However, now the purple floatingIndicator
is moving when the page is scrolled. I want it to remain fixed on the screen in the bottom-left corner of chatListContainer
(but still above inputBar
). Basically, I want the chatList
to be scrollable. I have spent hours now trying to figure out how to achieve this specific setup but to no avail. Does anyone know a trick or something to make it work?
3
Answers
Kastet's answer is good, but I tried some things out and actually found a way to fix it without moving
floatingIndicator
, and I'm quite puzzled why it works (especially theheight: 1%;
):You can move the "Text here" div into the inputBar div, and add some more styling for it:
A good use for sticky position