无法将聊天输入与 CSS 中 div 的底部对齐



我已经尝试了我能想到的所有方法,但就是行不通。我还是个初学者,所以请原谅我。这是一个聊天网站,我试着把输入框对齐到聊天框的底部。我试过"float: bottom;",无效。我试过像我读过的一些帖子建议的那样垂直对齐它的底部,但这也行不通。我被难住了,所以希望你能帮助我。

chat.view.tsx:

import { Message } from "./services/history.service";
export const ChatMessage = ({ username, text }: Message) => (
<div>
<b>{username}: </b>
<span>{text}</span>
</div>
);
export const ChatControlls = () => (
<div float="bottom" className="message-box">
<input placeholder="User" id="user-input" />
<input placeholder="Message" id="message-input" />
</div>
);
interface ChatProps {
messages: Message[];
}
export const Chat = ({ messages }: ChatProps) => (
<div className="chat">
<div className="container">
{messages.map((message, i) => (
<ChatMessage key={i} {...message} />
))}
</div>
<ChatControlls />
</div>
);

index.CSS:

max-height: 1080px;
min-height: 640px;
max-width: 1920px;
background-color: #daf4ff;
border-radius: 1rem;
border: 5px solid #444444;
vertical-align: bottom;
}
.chat .container {
overflow: overlay;
vertical-align: bottom;
}
input {
margin: 0;
max-width: 1920px;
flex: 1 0 auto;
outline: 0;
text-align: left;
line-height: 1.21428571em;
font-family: Lato, "Helvetica Neue", Arial, Helvetica, sans-serif;
padding: 0.67857143em 1em;
background: #fff;
border: 1px solid rgba(34, 36, 38, 0.15);
color: rgba(0, 0, 0, 0.87);
border-radius: 0.28571429rem;
vertical-align: bottom;
}
/* Message Box Crap */
.message-box {
display: grid;
grid-template-columns: 125px 2fr 70px;
vertical-align: bottom;
}
.message-box input:first-child {
border-top-right-radius: 0 !important;
border-bottom-right-radius: 0 !important;
border-color: transparent;
border-top-left-radius: 0 !important;
border-top-color: rgba(34, 36, 38, 0.15);
}
/* button styling */
.btn {
padding: 1em 2.1em 1.1em;
border-radius: 3px;
margin: 8px 8px 8px 8px;
color: #fbdedb;
background-color: #fbdedb;
display: inline-block;
background: #e74c3c;
-webkit-transition: 0.3s;
-moz-transition: 0.3s;
-o-transition: 0.3s;
transition: 0.3s;
font-family: sans-serif;
font-weight: 800;
font-size: 0.85em;
text-transform: uppercase;
text-align: center;
text-decoration: none;
-webkit-box-shadow: 0em -0.3rem 0em rgba(0, 0, 0, 0.1) inset;
-moz-box-shadow: 0em -0.3rem 0em rgba(0, 0, 0, 0.1) inset;
box-shadow: 0em -0.3rem 0em rgba(0, 0, 0, 0.1) inset;
position: relative;
}
.btn:hover,
.btn:focus {
opacity: 0.8;
}
.btn:active {
-webkit-transform: scale(0.8);
-moz-transform: scale(0.8);
-ms-transform: scale(0.8);
-o-transform: scale(0.8);
transform: scale(0.8);
}
.btn.block {
display: block !important;
}
.btn.circular {
border-radius: 50em !important;
}
/* Colours */
.red {
background-color: #d55050;
}
.teal {
background-color: #50d5a1;
}
.sky {
background-color: #6698cb;
}
.black {
background-color: #5c6166;
}
.gray {
color: black;
background-color: #d2d2d2;
}
.orange {
background-color: #e96633;
}
.pink {
background-color: #cb99c5;
}
.green {
background-color: #5bbd72;
}
.blue {
background-color: #7abedf;
}
.yellow {
background-color: #ecc92b;
}
.purple {
background-color: #564f8a;
}
/* body style*/
body {
background-color: #444444;
}

谢谢!

根据我的理解,你必须给你的message-box一个positionfixed

检查这个解决方案让div留在底部

最新更新