gpt4 book ai didi

html - 如何创建像 Facebook Messenger 这样的聊天气泡

转载 作者:太空狗 更新时间:2023-10-29 13:54:45 25 4
gpt4 key购买 nike

enter image description here

我将如何创建这样的聊天气泡。更具体地说,如何将一种类型的用户的两条或更多条连续消息作为一个整体分组到一个气泡中。例如对于发件人 - 第一条消息的右下边框为 0,中间的消息的右上、下边框为 0 边框半径,最后一条消息的右上边框为 0 边框半径。我必须使用 javascript 还是可以使用 css 来完成。

HTML 结构可以是

<ul>
<li class="him">By Other User</li>
<li class="me">By this User, first message</li>
<li class="me">By this User, secondmessage</li>
<li class="me">By this User, third message</li>
<li class="me">By this User, fourth message</li>
</ul>

我应该使用什么样的 CSS 类/样式?

最佳答案

这是一个相当基本的示例,但它应该可以解释您需要的所有基础知识。

大部分解决方案都在 + adjacent sibling selector 内.在这种情况下,它用于将不同的边框半径应用到来自同一个人的连续多条消息。

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;
}
<ul>
<li class="him">By Other User</li>
<li class="me">By this User, first message</li>
<li class="me">By this User, secondmessage</li>
<li class="me">By this User, third message</li>
<li class="me">By this User, fourth message</li>
</ul>

关于html - 如何创建像 Facebook Messenger 这样的聊天气泡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42256877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com