Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS overflow value for chat

Tags:

css

overflow

I build a chat application and i have an issue with the overflow property i think.. I want when a user connects to chat to show him the last message without him have to scroll down to the last message.When a user connects to chat by default it shows the first message and user have to scroll down. my css is:

.chat{
  height: 175px;
  width: 488px;
  margin: 0 auto;
  background-color: #000;
  padding: 20px 40px;
  border: solid 1px black;
  overflow: auto;
} 

Any suggestions?

like image 336
elias_t Avatar asked Jul 04 '26 08:07

elias_t


1 Answers

You can't do this purely with css, you'll need to use javascript.

var chatDiv = document.getElementsByClassName('chat')[0]; //I assume you only have one chat box!
chatDiv.scrollTop = chatDiv.scrollHeight;
like image 95
Matt Cain Avatar answered Jul 07 '26 14:07

Matt Cain