Structured chat interface with unchanging top and bottom sections

I'm currently trying to come up with a way to structure my chatbox so that it has a fixed header at the top and a fixed footer at the bottom, while allowing the chatbox body to scroll within those constraints. I've experimented with various approaches but haven't quite achieved the clean layout I desire.

.chat-head  {    
    background: red;
    position: fixed;
    top: 0;
    width:100%;
}
.chat-body  {
    position: relative;
    overflow-y: scroll;
    height: 93vh;
    margin: 25px 0;
    background:green;
}
.chat-foot {    
    background: blue;
    position: fixed;
    bottom: 0;
    width:100%;
}
<div class="col chat-head">
  One of three columns
</div>
  <div class="w-100 d-none d-md-block"></div>
<div class="col chat-body">chat<br>chat<br>chat<br>chat<br>...

View my JSFiddle for a live example: https://jsfiddle.net/aLysfspo/1/

Answer №1

To create a structured layout, include a .container with the following properties:

  1. padding-top should equal the height of the fixed header;
  2. padding-bottom should equal the height of the fixed footer;
  3. Ensure to reset all DOM nodes' margin and padding.

View the snippet below or visit this updated version on JSFiddle to see if it meets your requirements.

* {
  margin: 0;
  padding: 0;
}

.container {
  position: relative;
  width: 100%;
  height: 100vh;
  padding-top: 10vh;
  padding-bottom: 10vh;
  box-sizing: border-box;
}

.chat-head {
  background: red;
  position: fixed;
  top: 0;
  width: 100%;
  height: 10vh;
}

.chat-body {
  position: relative;
  overflow-y: scroll;
  height: 80vh;
  background: green;
}

.chat-foot {
  background: blue;
  position: fixed;
  bottom: 0;
  width: 100%;
  height: 10vh;
}
<div class="container">
  <div class="col chat-head">
    One of three columns
  </div>
  <div class="w-100 d-none d-md-block"></div>
  <div class="col chat-body">
    chat content...
  </div>
  <div class="w-100 d-none d-md-block"></div>
  <div class="col chat-foot">
    One of three columns
  </div>
</div>



Answer №2

It's important to keep in mind the usage of Bootstrap when working on this project. To maximize the benefits of using the framework, it's recommended to minimize the amount of custom CSS you write. Excessive custom styling could potentially interfere with the built-in features of Bootstrap, such as responsiveness.

To demonstrate, I've revised your code utilizing the Card Component and a spacing utility class. By incorporating the card component along with sections for header, body, and footer, I was able to achieve the desired layout without compromising core Bootstrap functionality. The addition of the spacing utility class py-0 ensured proper padding adjustments within the body section.

.chat .card-header {
  background: red;
}

.chat .card-body {  
  overflow-y: scroll;
  height: 50vh;
  background: green;
}

.chat .card-footer {
  background: blue;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<div class="card chat">
  <div class="card-header">
    One of three columns
  </div>
  <div class="card-body py-0">
    chat content here...
  </div>
  <div class="card-footer">
    One of three columns
  </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Incorporate Text, HTML, and Embed Images into PHPWord

I am currently utilizing PHPWord to create word documents using PHP. I have a specific content format that I need to adhere to, as shown below: Title Description Image1 Image1 Description(HTML CONTENT) Image2 Image2 Description(HTML CONTENT) As of now ...

What separates $(document).ready() from embedding a script at the end of the body tag?

Can you explain the distinction between running a JavaScript function during jQuery's $(document).ready() and embedding it in the HTML within script tags at the bottom of the body? Appreciate your insights, DLiKS ...

What is the formula to determine the precise hue-rotate needed for producing a particular shade?

I'm looking to change the color of a white background image in a div to match the main theme color. I know I can use filters like sepia(), saturate(10000%), and hue-rotate() to achieve this, but is there a way to calculate these values beforehand? Sin ...

Live notification application using node.js

I am looking to create a recipe maker webapp for practice purposes. This webapp will consist of 2 main pages: the index page and the recipes page. On the "index" page, users can create their own recipes. On the "recipes" page, users can view a table ...

Customize the design of a React Material-UI select dropdown by overriding

I am currently utilizing the React MUI Select Component for my forms, specifically for language selection. My issue arises when I need a different style for the dropdown menu of the language Select component. Overriding the relevant class would apply this ...

What is the method for sending a down arrow key in Capybara?

My unique requirement involves a specialized listbox automation that would benefit from simulating a down arrow keystroke and then pressing enter. The code snippet for pressing enter looks like this: listbox_example = find(input, "listbox-example") listb ...

Trouble encountered while trying to animate an SVG path

My attempt to animate an SVG is not working for some reason. https://i.stack.imgur.com/atTg3.png This is the component where I'm trying to load the SVG: import { JapanMap } from "../illustrations/japanMap"; export default function Home() ...

Transforming JSP style tags into CSS declarations

Within my JSP file, I have various tags that look like this: <style type="text/css"> #mask { display: none; cursor: wait; z-index: 99999; position: absolute; top: 0; left: 0; height: 100%; ...

Combining a standard JSS class with Material-UI's class overrides using the classnames library

I am exploring the method of assigning multiple classes to an element in React by utilizing the classnames package from JedWatson, along with Material-UI's "overriding with classes" technique. For reference, you can see an instance in MUI's docu ...

What to do when encountering a problem with HTML, CSS, and JS while loading a webpage from an SD card to a WebView

I am facing an issue while loading an HTML file from the SD card to a webview. The problem is that the CSS, images, and videos are not loading properly in the webview. Compatible with Android 4.4 KitKat and Chrome version Not compatible with versions belo ...

I am experiencing an issue where the close button image on tap is not closing on the first tap on

Why does the page close on the second tap instead of the first tap when using an iPhone? The image changes on tap but doesn't close as expected. $("#privacy-close-btn").mouseenter(function() { $("#privacy-close-btn").css("display", "none"); $(" ...

At what times do screen reader users utilize tabs?

Did you know that screen reader users often rely on specific keyboard shortcuts rather than tabs for navigating web pages? For example, in VoiceOver they may use CTRL + OPTION + Arrow Keys instead. This challenges the idea of optimizing for tabbable naviga ...

What is causing the radio button's background color not to change after it is selected?

I've been searching and exploring various solutions, but I'm encountering some difficulties with the following scenario: There are a few restrictions: Cannot utilize Javascript or Jquery. Must be achieved using pure CSS. My objective is to chan ...

Why is it that @font-face fails to function properly even after being defined correctly?

Here's the @font-face code I've been using: @font-face { font-family: "NotesEsa-Bold"; src: url("C:\Users\test\Desktop\Webpage\Fonts\NotesEsaBol.ttf") format("truetype"); /* Safari, Android, iOS */ font-we ...

What is the best way to integrate my company's global styles CDN for development purposes into a Vue cli project using Webpack?

After attempting to import through the entry file (main.js)... import Vue from 'vue' import App from '@/App' import router from '@/router/router' import store from '@/store/store' import BootstrapVue from 'boot ...

Converting an image to base64 format for storing in localStorage using Javascript

Currently, I am working on code that sets the background-image of a link. This is what I have so far: $("a.link").css("background-image", "url('images/icon.png')"); However, I want to enhance it by storing the image in localStorage: if (!local ...

Is it possible to continuously refresh a DIV element?

After spending the past 4 or 5 hours scouring Stack and various other resources, I am still unable to find a solution to my problem. The issue at hand involves an Iframe within a page that displays 5 lines of information fetched from a database. This info ...

Align the responsive image in the center of a container

I am facing a challenge in centering an image wrapped by an anchor tag inside a div. I have tried using display flexbox and justify-content:center for the image, which works to some extent. However, the height of the image remains constant while the width ...

The styles within a media query are not being successfully implemented

update: issue resolved. I discovered that there was a lingering media query in the css file that was meant to be removed. Also, I corrected some errors in the code. Thank you all for your help – it's now working perfectly. I have a set of html and ...

Scrollbar appearing in Safari (Windows) despite increasing the height

While working on a website for a client, I encountered an issue where a section within the footer is causing scrollbars to appear. Despite adjusting the height of the wrapper and setting overflow to hidden, the scrollbars persist. Is there anyone who can ...