纯CSS实现气泡效果

纯css实现一个气泡

HTML

<div id="bubble" class="bubble" style="background-color: rgb(42, 209, 172);"><i style="width: 0px;height: 0px;color: rgb(42, 209, 172);border-width: 14px 15px 8px 0px;border-style: solid;border-color: currentcolor transparent transparent;top: 91%;left: 0px;margin-bottom: 4px;"></i><div class="talk">Q</div></div>

CSS

.bubble
{
    position: absolute;
    top: 60px;
    right: 100px;
    /* width: 200px; */
    height: 35px;
    border-radius: 2px;
    background-color: currentColor;
    color: #fefefe;
}
.bubble i {
    position: absolute;
    border-width: 0;
    border-style: solid;
    border-color: transparent;
}
.bubble .talk {
    padding: 0px 20px;
    color: #fff;
    font-size: 20px;
    font-family: none;
}

最后呈现效果
在这里插入图片描述
ok,完活,需要的时候直接拿,高效,哈哈哈!

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现聊天窗气泡效果,可以使用以下的CSS样式: HTML结构: ```html <div class="chat-container"> <div class="chat-message received"> <div class="message-bubble"> <span class="message">Hello!</span> </div> </div> <div class="chat-message sent"> <div class="message-bubble"> <span class="message">Hi there!</span> </div> </div> <div class="chat-message received"> <div class="message-bubble"> <span class="message">How are you?</span> </div> </div> <div class="chat-message sent"> <div class="message-bubble"> <span class="message">I'm good, thanks. How about you?</span> </div> </div> </div> ``` CSS样式: ```css .chat-container { display: flex; flex-direction: column; padding: 20px; background-color: #eee; height: 400px; overflow-y: scroll; } .chat-message { display: flex; margin-bottom: 10px; } .received { align-self: flex-start; } .sent { align-self: flex-end; } .message-bubble { background-color: #fff; border-radius: 10px; padding: 10px; box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1); position: relative; } .message-bubble:before { content: ""; position: absolute; top: 0; border-style: solid; border-width: 0 10px 10px 0; } .received .message-bubble:before { left: -10px; border-color: #fff transparent transparent transparent; } .sent .message-bubble:before { right: -10px; border-color: #007bff transparent transparent transparent; } .message { line-height: 1.5; font-size: 14px; } ``` 解释: - `chat-container`是聊天窗的容器,设置了`flex`布局和垂直方向的排列,以及一些基本的样式,如背景色、高度和滚动条等。 - `chat-message`是每个聊天消息的容器,设置了`flex`布局和一些基本的样式,如外边距等。 - `.received`和`.sent`分别表示接收到的消息和发送的消息,设置了不同的对齐方式。 - `message-bubble`是消息气泡的容器,设置了一些基本的样式,如背景色、边框半径、内边距和阴影等,以及相对定位。 - `.message-bubble:before`是消息气泡的三角形,使用`content`属性来插入一个空内容,设置了绝对定位、上边距、边框样式和边框宽度,并根据消息的来源设置了不同的位置、边框颜色和方向。 - `message`是消息内容的容器,设置了一些基本的样式,如行高和字体大小等。 这些样式可以根据实际需求进行调整,以达到更好的效果

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值