Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create chat bubbles like facebook Messenger

Tags:

html

css

chat

enter image description here

How would I create chat bubbles like this. More specifically how to group two ore more consecutive messages by one type of user into a bubble as a whole. For example FOR THE SENDER - the first message has right bottom border a 0, the messages in between have right top,bottom as 0 border radius and the last one has top right 0 border radius . Do I have to use javascript or can it be done using css.

HTML structure ca be

<ul>
 <li class="him">By Other User</li>
 <li class="me">By this User, first message</li>
 <li class="me">By this User, secondmessage</li>
 <li class="me">By this User, third message</li>
 <li class="me">By this User, fourth message</li>
</ul>

What kind of css class/styles should i be using?

like image 434
Raj Nandan Sharma Avatar asked Feb 15 '17 18:02

Raj Nandan Sharma


People also ask

How do you make chat heads bubble?

Turn on bubble notifications for the Android Messages app Your text messages will appear as bubbles that you can drag around the screen. Navigate to and open Settings, and then tap Notifications. Tap Advanced settings, tap Floating notifications, and then choose Bubbles.

Are bubbles the same as chat heads on messenger?

Multiple users on /r/Android spotted that the Android 11 Bubbles have stopped working in recent versions of the app and have been replaced by Facebook Messenger's chat heads.

How do I make a chat head?

Tap on your profile picture in the upper-left corner of the screen. Scroll down the menu and find the Chat Heads option. Toggle the switch until it turns blue to enable chat heads, or toggle it until grey to disable them.

How do you add a messenger bubble?

1] On your phone, head to Settings > Apps and Notifications > See all apps. 2] Here, select the app which supports the feature, for example, Messenger. 3] Click on Bubbles under Notifications, and select “All conversations can bubble.”


1 Answers

This is a rather basic example but it should explain all of the fundamentals you require.

Most of the solution lies within + adjacent sibling selector. In this case, it's used to apply a different border radius to multiple messages in a row from the same person.

ul{
  list-style: none;
  margin: 0;
  padding: 0;
}

ul li{
  display:inline-block;
  clear: both;
  padding: 20px;
  border-radius: 30px;
  margin-bottom: 2px;
  font-family: Helvetica, Arial, sans-serif;
}

.him{
  background: #eee;
  float: left;
}

.me{
  float: right;
  background: #0084ff;
  color: #fff;
}

.him + .me{
  border-bottom-right-radius: 5px;
}

.me + .me{
  border-top-right-radius: 5px;
  border-bottom-right-radius: 5px;
}

.me:last-of-type {
  border-bottom-right-radius: 30px;
}
<ul>
 <li class="him">By Other User</li>
 <li class="me">By this User, first message</li>
 <li class="me">By this User, secondmessage</li>
 <li class="me">By this User, third message</li>
 <li class="me">By this User, fourth message</li>
</ul>
like image 85
Serg Chernata Avatar answered Oct 09 '22 18:10

Serg Chernata