CSS实现类似微信的聊天气泡

实现完整代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat Bubble Example</title>
<style>
    body {
        font-family: Arial, sans-serif;
        background-color: #f5f5f5;
        padding: 20px;
    }

    .chat-container {
        display: flex;
        flex-direction: column;
        max-width: 600px;
        margin: 0 auto;
    }

    .chat-bubble {
        position: relative;
        padding: 10px 15px;
        border-radius: 10px;
        margin: 10px 0;
        max-width: 70%;
        line-height: 1.5;
    }

    .chat-bubble.left {
        background-color: #e5e5ea;
        align-self: flex-start;
    }

    .chat-bubble.left::before {
        content: '';
        position: absolute;
        top: 15px;
        left: -10px;
        width: 0;
        height: 0;
        border: 10px solid transparent;
        border-right-color: #e5e5ea;
        border-left: 0;
        border-top: 0;
        margin-top: -5px;
    }

    .chat-bubble.right {
        background-color: #007aff;
        color: white;
        align-self: flex-end;
    }

    .chat-bubble.right::before {
        content: '';
        position: absolute;
        top: 15px;
        right: -10px;
        width: 0;
        height: 0;
        border: 10px solid transparent;
        border-left-color: #007aff;
        border-right: 0;
        border-top: 0;
        margin-top: -5px;
    }
</style>
</head>
<body>

<div class="chat-container">
    <div class="chat-bubble left">
        你好!这是一个左边的聊天气泡。
    </div>
    <div class="chat-bubble right">
        你好!这是一个右边的聊天气泡。
    </div>
    <div class="chat-bubble left">
        这个气泡的样式和微信聊天类似。
    </div>
    <div class="chat-bubble right">
        是的,我们可以通过CSS轻松实现这个效果。
    </div>
</div>

</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值