3

I am trying to make a content slider with a chatbox to the side and a footer stuck to the bottom.

Here is a diagram of what I am trying to achieve:

enter image description here

The problem with below code is that the chatbox is the height of the page. I want the chat box to stop at the footer so that it is the height of the page -60px.

And here is what I have so far:

body {
  margin: 0;
}

.wrapper {
  background: #95a5a6;
  display: table;
  height: 100vh;
  width: 100%;
}

.wrapper-inner {
  display: table-cell;
  padding-left: 300px;
  padding-bottom: 60px;
  vertical-align: middle;
  text-align: center;
}

.chatbox {
  background: #bdc3c7;
  min-height: 100%;
  position: absolute;
  overflow-x: hidden;
  overflow-y: auto;
  width: 300px;
  z-index: 2;
}

.footer {
  background: #2c3e50;
  bottom: 0px;
  height: 60px;
  position: absolute;
  width: 100%;
  z-index: 1;
}
<div class="wrapper">
  <div class="chatbox"></div>
  <div class="wrapper-inner">Content</div>
</div>
<div class="footer"></div>

https://jsfiddle.net/bjxsyve7/4/

Jethro Hazelhurst
  • 3,010
  • 7
  • 33
  • 74

3 Answers3

2

You can use CSS calc() to achieve this. Add this min-height: calc(100% - 60px) to .chatbox. For more info about calc().

body {
  margin: 0;
  overflow-x:hidden;
}

.wrapper {
  background: #95a5a6;
  display: table;
  height: 100vh;
  width: 100%;
}

.wrapper-inner {
  display: table-cell;
  min-height: 100%;
  padding-left:300px;
  padding-bottom: 60px;
}

.chatbox {
  background: #bdc3c7;
  min-height: calc(100% - 60px);
  position: absolute;
  overflow-x: hidden;
  overflow-y: auto;
  top:0;
  width: 300px;
  z-index: 2;
}

.footer {
  background: #2c3e50;
  bottom: 0px;
  height: 60px;
  position: absolute;
  width: 100%;
  z-index: 1;
}
<div class="wrapper">
  <div class="chatbox"></div>
  <div class="wrapper-inner"></div>
</div>
<div class="footer"></div>
2

Here's a simplified version using only flex and calc():

body {
  display: flex;
  flex-wrap: wrap;
  margin: 0;
}

.chatbox {
  flex: 0 0 300px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  background-color: #bdc3c7;
}

.content {
  flex: 1;
  background-color: #95a5a6;
}

.footer {
  flex-basis: 100%;
  height: 60px;
  background: #2c3e50;
}
<div class="chatbox"></div>
<div class="content">Content</div>
<div class="footer"></div>

jsFiddle

Michael Benjamin
  • 307,417
  • 93
  • 525
  • 644
1

You need only adding this:

.wrapper{
  position: relative;
}

In your code the chatbox div has height 100% of the body. But if you set position: relative; to it's parent(.wrapper) it will have height 100% of it's parent.

This is an easy way to do this with flex:

body {
  display: flex;
  flex-direction:column;
  min-height: 100vh;
}

.wrapper {
  background: #95a5a6;
  display: flex;
  flex: 1;  
}

.chatbox {
  background: #bdc3c7; 
  overflow-x: hidden;
  overflow-y: auto;
  width: 200px;
}

.footer {
  background: #2c3e50;
  height: 60px;
}
<div class="wrapper">
    <div class="chatbox"></div>
    <div class="wrapper-inner">Content</div>
</div>
<div class="footer"></div> 
Farzin Kanzi
  • 3,320
  • 2
  • 19
  • 21