这是一个聊天室,里面有一个div.words作为容器,还有一个.content div。
我想从.content的底部显示文本,所以我使用position:absolute,bottom:0;on.content。但我想让它显示滚动条如果。内容增长高于。字。所以我添加溢出:自动打开。单词。
如果删除底部:0,溢出:自动将正常工作。但如果底部为0,则不起作用。
如何使输入从底部显示,并在溢出时有滚动条?
CSS:
.tbchat-room{
position: fixed;
bottom:0;
width:260px;
border:1px solid #aaa;
background:#fff;
}
.tbchat-room .head{
padding: 3px 10px;
background:#3d9ac1;
color:#fff;
}
.tbchat-room .words{
height:230px;
background:#ececec;
overflow:auto;
position:relative;
}
.tbchat-room .words .content{
position:absolute;
}
.tbchat-room .say{
width:246px;
margin:0;
border-top: 1px solid #ccc;
border-bottom: 0;
border-left: 0;
border-right: 0;
padding:4px 6px;
}
.pull-right{
float:right;
}
.content{
padding:5px 10px;
}
HTML格式:
<div class="tbchat-room">
<div class="head">
<span class="title">Chat Room</span>
<a class="room-close-button pull-right">×</a>
</div>
<div class="words">
<div class="content">
<div>sample text</div>
<div>sample text</div>
</div>
</div>
<input class="say" type="text"/>
</div>
http://jsfiddle.net/s8jD5/
最佳答案
每次向框中添加新的聊天消息时,请尝试保持overflow-y:auto
并运行此jquery语句
$('.words').scrollTop($('.words')[0].scrollHeight);
你将永远处于最底层