How to create chat bubbles like facebook Messenger

后端 未结 4 460
孤独总比滥情好
孤独总比滥情好 2020-12-08 16:38

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

4条回答
  •  庸人自扰
    2020-12-08 17:03

    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;
    }
    • By Other User
    • By this User, first message
    • By this User, secondmessage
    • By this User, third message
    • By this User, fourth message

提交回复
热议问题