Jac*_*Jou 5 html css scroll vertical-alignment
这是一个聊天室,有一个 div .words 作为容器,里面有一个 .content div。
我希望文本从 .content 的底部显示,所以我使用position:absolute,bottom:0; 关于.内容。但我希望它在 .content 增长高于 .words 时显示滚动条。所以我在.words 上添加了overflow:auto。
如果我删除bottom:0,overflow:auto将正常工作。但如果bottom: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;
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
overflow-y:auto每次当新的聊天消息添加到框中时,尝试保留并运行此 jQuery 语句
$('.words').scrollTop($('.words')[0].scrollHeight);
Run Code Online (Sandbox Code Playgroud)
你将永远处于最底层