基本上,我是想让聊天信息可以滚动。然而,到目前为止,内容似乎无法滚动。当“聊天消息包装器”类是相对的时,它会滚动得很好,但是,我希望聊天消息最初出现在底部,这就是为什么我将它切换到绝对。
Html:
<div class="chat-widget">
<div class="header">Social Chat</div>
<div class="chat-messages-wrapper">
<div class="chat-message">
<img class="profile-image" src="../Content/images/facebook-profile.png" /> <span class="header-1">
<img class="logo" src="../Content/images/facebook-logo.png" />
<span class="username">Jens Olsen says:</span>
</span> <span class="header-2">
<button class="reply btn btn-primary btn-xs">Reply</button>
<button class="like btn btn-success btn-xs">Like</button>
<button class="spam btn btn-danger btn-xs">Spam</button>
<span class="date">5:03PM</span>
</span>
<div class="text">This is the chat message. This is the chat message.</div>
</div>
<div class="chat-message">
<img class="profile-image" src="../Content/images/facebook-profile.png" /> <span class="header-1">
<img class="logo" src="../Content/images/twitter-logo.png" />
<span class="username">Jens Olsen says:</span>
</span> <span class="header-2">
<button class="reply btn btn-primary btn-xs">Reply</button>
<button class="like btn btn-success btn-xs">Like</button>
<button class="spam btn btn-danger btn-xs">Spam</button>
<span class="date">5:03PM</span>
</span>
<div class="text">This is the chat message. This is the chat message.</div>
</div>
<div class="chat-message">
<img class="profile-image" src="../Content/images/default-avatar.png" /> <span class="header-1">
<span class="username">Jens Olsen says:</span>
</span> <span class="header-2">
<button class="reply btn btn-primary btn-xs">Reply</button>
<button class="like btn btn-success btn-xs">Like</button>
<button class="spam btn btn-danger btn-xs">Spam</button>
<span class="date">5:03PM</span>
</span>
<div class="text">This is the chat message. This is the chat message.</div>
</div>
</div>
<div class="reply-box">
<input class="reply-text" placeholder="Type your message here..." />
<button class="btn btn-primary reply-button">Send</button>
</div>
</div>Css:
.chat-widget {
position: fixed;
right: 5px;
bottom: 5px;
height: 95%;
width: 300px;
background-color: #FFF;
border: solid 3px #3B5998;
overflow: hidden;
}
.chat-widget .header {
text-align: center;
font-size: 18px;
color: #FFF;
background-color: #3B5998;
font-weight: bold;
padding-top: 5px;
padding-bottom: 5px;
}
.header {
position: relative;
z-index: 2;
width: 100%;
}
.chat-messages-wrapper {
position: absolute;
bottom: 40px;
padding-left: 7px;
padding-right: 7px;
height: auto;
overflow-y: auto;
}
.chat-message {
padding-top: 5px;
position: relative;
border-bottom: solid 1px #000;
overflow-y: auto;
}
.chat-message .profile-image {
height: 48px;
width: 48px;
border: solid 1px #000;
margin-right: 5px;
}
.chat-message > .header-1 {
position: absolute;
height: 20px;
}
.chat-message > .header-1 .logo {
width: 75px;
height: 20px;
}
.chat-message > .header-1 .username {
font-weight: bold;
}
.chat-message > .header-2 {
position: absolute;
top: 30px;
height: 20px;
}
.chat-message > .header-2 > .reply {
width: 50px;
}
.chat-message > .header-2 > .like {
width: 50px;
}
.chat-message > .header-2 > .spam {
width: 50px;
}
.chat-message > .header-2 .date {
font-style: italic;
position: relative;
right: 0px;
}
.chat-message .text {
position: relative;
margin: 5px;
}
.chat-message:last-child {
border-bottom: 0px;
}
.reply-box {
overflow-y: auto;
position: absolute;
bottom: 5px;
}
.reply-box .reply-text {
width: 70%;
height: 32px;
}
.reply-box .reply-button {
width: 25%;
}下面是一个包含完整代码的JSFiddle:http://jsfiddle.net/5GCE5/1/
发布于 2014-04-01 14:34:41
为了使overflow-y工作,您需要为.chat-messages-wrapper元素指定一个显式(min/max) height。
但是,由于该框的位置是绝对的,您可以使用top和bottom属性来达到同样的效果:
这里的例子
.chat-messages-wrapper {
position: absolute;
padding-left: 7px;
padding-right: 7px;
/* height: auto; */
bottom: 40px; /* = height of bottom element */
top: 32px; /* = height of top element */
overflow-y: auto;
}发布于 2014-04-01 14:32:19
你需要给.chat-messages-wrapper一个max-height
http://jsfiddle.net/5GCE5/6/
https://stackoverflow.com/questions/22788803
复制相似问题