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 exampl
Here is a pure css solution, but it hinges on your ability to detect and apply the chat__bubble--stop class when the final message of a group is sent. Unfortunately the pseudo class :last-of-type can't be used; as others have pointed out, the last message in a group isn't necessarily the last of the conversation. It also makes use of the adjacent sibling selector (+).
.chat {
list-style-type: none;
width: 20em;
}
.chat__bubble {
margin-bottom: 3px;
padding: 5px 10px;
clear: both;
border-radius: 10px 10px 2px 2px ;
}
.chat__bubble--rcvd {
background: #f2f2f2;
color: black;
float: left;
border-bottom-right-radius: 10px;
}
.chat__bubble--sent {
background: #0066ff;
color: white;
float: right;
border-bottom-left-radius: 10px;
}
.chat__bubble--sent + .chat__bubble--sent {
border-top-right-radius: 2px;
}
.chat__bubble--rcvd + .chat__bubble--rcvd {
border-top-left-radius: 2px;
}
.chat__bubble--stop {
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
}
- What are you up to?
- Not much.
- Just writing some CSS.
- I just LOVE writing CSS.
- Do you?
- Yeah!
- It's super fun.
- ... SUPER fun.