Tips on positioning a div at the bottom of another div so that it remains fixed while the parent div is scrolled

I'm currently working on developing a messaging app similar to WhatsApp. In the app, I have a parent div that holds the messages, and a child div that contains the text field and send button. My goal is to keep the text field and button at the bottom of the parent container even when scrolling through messages. I've tried using Bootstrap 4's fixed bottom class, but it hasn't been successful...

I've also come across other solutions on Stack Overflow suggesting to use position: relative; in the parent and position: absolute in the child div, but that hasn't worked either.

This is the code for my parent container:

<div class="container justify-content-center w-50 position-relative" style="height: 400px; overflow-y: auto;">
<app-message-container></app-message-container>
</div>

And here is the code for the child container, i.e., app-message-container:

<div class="container d-flex fixed-bottom position-absolute">
<input class="form-control" type="text" placeholder="Enter Text">
<button class="btn btn-success">Send</button>
</div>

Thank you in advance.

Answer №1

To ensure proper positioning, it is recommended to eliminate the position-absolute and position-relative classes if you are already utilizing the fixed-bottom class (which applies position: fixed in your scenario).

<div class="container d-flex fixed-bottom">

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container justify-content-center w-50" style="height: 400px; overflow-y: auto; ">  
  <div class="container d-flex fixed-bottom">
     <input class="form-control" type="text" placeholder="Enter Text">
     <button class="btn btn-success">Send</button>
  </div>
  <p>Alias inventore doloremque inceptos soluta, aliqua quaerat totam 
  sccusantium quibusdam dolor vestibulum. Class? Non sapiente exercitation 
  libero quaerat hic sociis voluptas laboris! Interdum nemo mattis posuere 
  fermentum mus auctor iaculis adipisci? Blandit.</p>
</div>

Answer №2

How to Implement a Fixed Position Div Inside a Relative Position Container with Overflow Y Scroll

Check out this resource for more information:

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

CSS exclusive - achieving a horizontal scrolling list with all list items in a single row

I am working with a div that has a fixed width. Inside this div, there is an unordered list (ul) containing a random number of list items (li) with varying widths. My project utilizes the Bootstrap framework. Below is an example of the code structure: & ...

Placing an order and obtaining the associated reservation_id through the use of SQL, PHP, and an html5 form

I have multiple forms with distinct purposes: The first form collects information such as the reservation date, customer details, and the table assigned for that specific date. In the second form, I capture data to place an order. This includes entering ...

A difference in the way content is displayed on Firefox compared to Chrome, Edge, and Safari

Recently, I encountered an issue with a tool I had developed for generating printable images for Cross-Stitch work. The tool was originally designed to work on Firefox but is now only functioning properly on that browser. The problem at hand is whether th ...

Tips for extracting and utilizing the values of multiple checked checkboxes in a jQuery datatable

When a button is clicked, I am trying to retrieve the selected values of multiple rows from the datatables. However, with my current code below, I am only able to get the value of the first selected row. function AssignVendor() { var table = $(assig ...

Ensure that the spacing between rows matches the spacing between columns

I am working on creating a 3x3 grid using Bootstrap. My goal is to have consistent spacing between the rows and columns. How can I achieve this effectively? ...

Discover the Magic of CSS Animation

I am not experienced in CSS animations and have limited knowledge about animations. I am trying to create an animation where a grey box slides down from the top line above the login/register section, but currently it only fades in. If anyone can provide an ...

Is there a way to dynamically toggle the visibility of a floating textarea between on and off?

I have my own blog website: Essentially, what I am aiming for is When a user clicks on the search button, a floating semi-transparent textarea window should appear inside the designated rectangle area (as shown in the image, that red orange rectangle). ...

Align an image with text using CSS and HTML

I'm having trouble with my CSS and HTML code. I want to align the text to the right of an image in a grid format, but it keeps appearing below the image instead. Here is the code snippet: <html> <head> <style type="text/css"> #conta ...

Automatically trigger a PHP reload/refresh based on user input

My website has a form that populates a table with data. Currently, after the user submits the data, they have to manually refresh the page in order to see the new data displayed. Is there a way to automatically refresh the table every time the user hits ...

Click on link after animation has finished

I'm currently facing an issue with my script not functioning correctly. The code I'm utilizing is from a resource provided by Codyhouse to implement a 3D rotating navigation menu on my webpage. Essentially, when you click the hamburger icon, it o ...

Tips for resolving the error "Invalid value for style prop - must be an object" in a React.js and CSS scenario

Hey there, I'm currently working with module.css in React and facing an issue when trying to include the following line: <span style="--i:1;"><img src="https://i.postimg.cc/BQcRL38F/pexels-photo-761963.jpg" alt="not f ...

AngularJS: Showcase HTML code within ng-view along with its corresponding output displayed in a navigation format such as Html, Css, JS, and Result

Currently, I am working on a web application. One of the screens, screen-1, consists of a series of buttons labeled 'Code'. When a user clicks on any of these buttons, it loads a different HTML page, screen-2, in the ng-view using $location.path( ...

Tips For Making Your Bootstrap 4 Page Fit Perfectly on Mobile Screens

Currently in the process of developing . The frontpage has been created and tested using Chrome's dev console's device toolbar. Ensured that the correct viewport is set and utilized Bootstrap's column system for stacking elements. However, ...

What is the best way to display the panel during a postback?

I have a group with two radio buttons labeled purchase and expenses. When the purchase radio button is clicked, the panelpurchase will be displayed, and similarly, the panelexpense will show for the expenses radio button. Check out the image of the output ...

Material-UI: Eliminate the missingOppositeContent:before element from TimelineItem

I'm currently using Material-UI to construct a timeline. Here is the code snippet I am working with: <Timeline align="right" className={classes.monthlyContainer}> <TimelineItem > <TimelineSeparator className={class ...

Button from Material-UI vanishes upon being clicked

I encountered an issue with a button that disappears when clicked on. Additionally, clicking the button once does not trigger any actions associated with it. In order to execute the button actions, I have to click the area where the button was located afte ...

Ways to implement a placeholder height for images on a webpage with varying heights using HTML

I'm facing an issue with an image on my website that has a dynamic width and height as defined by the following CSS: .sm_item_image { width:100%; height:auto; max-width:400px; } The problem arises when the image takes some time to load, ...

Can CSS alone be used to provide a cover for auto-scaling images?

One common technique is using max-height and max-width to make an image automatically fit in a div, as shown below: .cover img { max-width: 100%; max-height: 100%; } But is there a way to create a translucent cover (with opacity set to 0.8) that ...

Retrieving the value of a <select> element using React.useState in a Nextjs environment

Encountering an issue in Nextjs involving the useState function from React. There is a select element with multiple options. Upon selection, the useState should store the value of the selected option. const [value, setValue] = useState('') ... ...

When working on a node.js project with Angular, I'm considering incorporating a new HTML framework such as Foundation Zurb or Bootstrap. Is this a good idea, or should I stick

Is it necessary to use an additional HTML framework like Foundation Zurb or Bootstrap when using Angular in a node.js project? Can Angular alone handle the functionalities provided by Foundation Zurb / Bootstrap? Your insights would be greatly appreciated ...