聊天对话气泡-字体自适应气泡宽度

本文展示了如何使用CSS3创建聊天对话气泡,并确保气泡宽度能根据字体内容自适应调整。通过示例代码,可以看到不同类型的对话气泡(发送者和接收者)以及如何利用伪元素添加‘尾巴’。内容涵盖了长文本的处理,确保在网页和手机端都有良好的显示效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  <style>
    .sender {
        overflow: hidden;
        position: relative;
         margin-bottom: 20px;
    }

    .sender>div:nth-of-type(1) {
        position: absolute;
    }

    .sender>div:nth-of-type(2) {
        min-width: 100px;
        padding: 0 55px;
        line-height: 23px;
    }

    .sender div.bg {
        margin: 0 20px 10px 15px;
        border-radius: 7px;
        padding: 10px;
        display: inline-block;
        position: relative;
        background-color: aquamarine;
    }

    .receiver div:first-child img,
    .sender div:first-child img {
        width: 50px;
        height: 50px;
    }

    .receiver {
        overflow: hidden;
        position: relative;
         margin-bottom: 20px;
    }

    .receiver>div:nth-child(1) {
        position: absolute;
        right: 0;
    }

    .receiver>div:nth-of-type(2) {
        min-width: 100px;
        padding: 0 55px;
        line-height: 23px;
    }

    .receiv
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值