gpt4 book ai didi

html - 聊天框中的 CSS

转载 作者:太空宇宙 更新时间:2023-11-04 04:54:42 24 4
gpt4 key购买 nike

我有一个聊天程序,我的目标是,当有人键入并发送文本时,我希望文本从底部显示。像任何其他聊天框一样。为此,我编写了以下 html/css 结构。这里的“li”标签是在有人发送文本时动态创建的。

问题:

问题是如果我从“.chatbox ul”中删除“height:100%”,聊天框中的文本将从底部开始。但在那种情况下,我看不到任何滚动条。但我需要看到一个滚动条。而且,如果我在“.chatbox ul”中保留“height:100%”,我会看到一个滚动条,但聊天框中的文本从顶部开始。

我的目标是有一个滚动条,文本也应该从底部开始。我将如何实现这一点..?有什么帮助吗??

<div class="chatBox">
<ul id="messages" class="chatText">
<li>
<div class="chatterName">maverick </div>
<div class="chatterMessage"> hi</div>
<div class="clear"></div>
</li>

<li>
<div class="chatterName">johny</div>
<div class="chatterMessage"> hello</div>
<div class="clear"></div>
</li>
</ul>

CSS:

.chatBox
{
background-image: url('../images/DefaultitemBg.gif');
font-family: Verdana;
font-size: 14px;
color: #333333;
border: 1px double #FFFFFF;
padding: 5px;
margin: 10px;
width:76%;
height:600px;
position:relative;
border: 1px solid #E9E9E9;
overflow:auto;
float:left;

}
.chatBox ul
{
list-style-type: none;
padding: 0px;
margin: 0px;
position:absolute;
overflow:auto;
bottom:0;
height:100%;
}
.chatBox ul li
{
border-bottom-style: solid;
border-bottom-width: 1px;
border-bottom-color: #F2F2F2;
margin-bottom: 0px;
}
.chatterName
{
width: 120px;
background-color: #EEEEEE;
color: #333333;
float: left;
border-right-style: solid;
border-right-width: 1px;
border-right-color: #CCCCCC;
height: 30px;
border-bottom-style: solid;
border-bottom-width: 1px;
border-bottom-color: #E6E6E6;
}
.chatterMessage
{
width: 91%;
padding-left:4px;
color: #333333;
float:left;
min-height:30px;
border-bottom-style: solid;
border-bottom-width: 1px;
border-bottom-color: #EFEFEF;
}
.chatText
{
bottom: 0;
left: 0;
border-top-style: 0;
border-right-style: 0;
border-bottom-style: 1;
border-left-style: 0;
border-bottom-width: 1px;
border-bottom-color: #E6E6E6;

width:100%;

编辑:

See it live here

如果你仔细看,你会注意到当我在聊天框中输入文本时,从顶部开始,之前的文本正在消失。我想要的是一个滚动条,以便用户可以看到以前的消息。

最佳答案

您可以使用 javascript 滚动到底部:

document.getElementById('messages').innerHTML += '<li>'+your message here+'</li>'
window.scrollTo(0, document.body.scrollHeight)

关于html - 聊天框中的 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12709744/

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