javascript - 如何让输入栏粘在 div 容器的底部?
问题描述
我试图让输入栏留在 div 容器的底部,但我不知道如何做到这一点。有什么帮助吗?
import React, { Component } from 'react';
import './App.css';
import './NameBox';
class ChatBox extends Component {
render() {
return (
<div>
<div className="chat-box-container">
<div className="chat-box">
<h1>Chat Room</h1>
<div style={{/*GET THIS TO STICK TO BOTTOM OF THE DIV ABOVE*/}}>
<div className="input-group mb-3">
<input id="name" type="text" class="form-control" placeholder="Name"/>
<div className="input-group-append">
<a href="/chat" onClick={this.getName} className="btn btn-success" type="button">Enter</a>
</div>
</div>
</div>
</div>
</div>
<p>{localStorage.getItem("username")} has entered the chat...</p>
</div>
);
}
}
export default ChatBox;
解决方案
我知道您的代码在 React 和 JSX 中,但只是作为一般答案。要相对于div定位某些内容,您需要提供父 div position: relative
,然后对于输入栏,您可以将输入栏放置在底部。position: absolute
bottom: 0
<div style="
position: relative;
width: 200px;
height: 200px;
border: 1px solid black;"
>
<input type="text"
style="
position: absolute;
bottom: 0;"
placeholder="Entry Bar"
/>
</div>
推荐阅读
- python - 在matplotlib python的散点图中注释每个数据点
- android - 在 onLongPress 事件之后,ListView 如何在没有 onScroll 事件的情况下继续滚动
- php - 为什么 Geoip 返回 int 而不是 float?
- indexing - 从另一个数据框中过滤具有正确索引的行
- android - 添加多行文本视图的可绘制开头
- python - np.concatenate 错误...ValueError:所有输入数组必须具有相同的维数
- javascript - 如何在 nativescript 中定义默认的 TabView?
- image - 如何使用 jpeg 在压缩图像中找到 jpeg 标头
- python - 如何在 ListView 中包含 CreateView 模板?
- javascript - 如何在 Python 中解析 html 源代码中的 javascript 代码?