首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >chatbox中的css

chatbox中的css
EN

Stack Overflow用户
提问于 2012-10-03 21:38:56
回答 2查看 8.7K关注 0票数 0

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

问题是:

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

我的目标是有一个滚动条,文本也应该从底部开始。我怎么才能得到这个..??有帮手吗??

代码语言:javascript
复制
<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:

代码语言:javascript
复制
.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

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-10-03 22:28:54

这应该可以解决这个问题:

使用max-height而不是height

代码语言:javascript
复制
.chatBox ul
{
list-style-type: none;
padding: 0px;
margin: 0px;
position:absolute;
overflow:auto;
bottom:0;
max-height: 100%;
/*height:100%;*/
}

工作示例:http://jsfiddle.net/pt43J/1/

票数 0
EN

Stack Overflow用户

发布于 2012-10-03 21:47:11

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

代码语言:javascript
复制
document.getElementById('messages').innerHTML += '<li>'+your message here+'</li>'
window.scrollTo(0, document.body.scrollHeight)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12709744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档