Force a DIV element into the bottom

Asked

Viewed 4,389 times

0

Good morning, everyone.

I need to align elements at the bottom of a mother div.

This is a chat screen that messages are displayed whenever there are new ones at the bottom of the window.

However, I can not force the positioning at the bottom, as for example it would be in Whatsapp that when typing and sending messages, are at the bottom.

Does anyone have any tips on how to do this?

NOTE: I am not using flex. Only relative and absolute positioning.

2 answers

2


Buddy, I had a chat last month and I didn’t bother to leave the messages in the bottom, I just printed them from the oldest to the newest one under the other and I forced the DIV SCROLL always down. This will work in your need, just put the parent DIV in Absolute and the messages with fixed width so as to use more than 50% of the width of the parent DIV, so the messages will be printed one under the other.

Look how it turned out: CHAT - Alisson Pelizaro

  • 1

    Thanks. Very good tip Alisson.

1

The container must have relative positioning and the element to fix absolute positioning:

CSS:

.container {
  width: 100%;
  height: 300px;
  position: relative;
  background: #ccc
}

.elemento {
  width: 30%;
  height: 20px;
  background-color: #000000;
  position: absolute;
  bottom: 0;
  left: 0;
}

HTML:

<div class="container">
   <div class="elemento"></div>
</div>
  • Thank you. That’s what I imagined. But in my code it’s failing for some reason I have to analyze. But that’s it. I’m grateful.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.