gpt4 book ai didi

html - 绝对 child 不可滚动

转载 作者:太空宇宙 更新时间:2023-11-04 03:56:09 25 4
gpt4 key购买 nike

基本上,我正在尝试使聊天消息可滚动。然而,截至目前,内容似乎不可滚动。当“chat-messages-wrapper”类是相对的时,它会滚动得很好,但我希望聊天消息最初出现在底部,这就是我将其切换为绝对的原因。

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/

最佳答案

为了得到overflow-y要工作,您需要为 .chat-messages-wrapper 元素指定一个明确的(最小/最大)height

但是,由于盒子是绝对定位的,您可以使用 topbottom 属性来实现相同的效果:

Example Here

.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;
}

关于html - 绝对 child 不可滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22788803/

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