html - 根据按钮大小自动调整输入大小?
问题描述
我在同一个 div 中有一个input
和一个button
,并且希望它们在一行中没有任何间隙,无论屏幕大小如何,但无法实现。该按钮似乎有一个水平填充,尽管我将padding
和都设置margin
为none
,所以 % 不会是一个解决方案。另外,我希望按钮环绕其内容,因此即使它可以工作,也不是最好的解决方案。有没有办法设置按钮的位置和大小,并使用 CSS 相应地调整输入的大小?或者是否需要一些 JavaScript 来执行此操作?
期望的输出:
电流输出:
当前代码(CSS 无关紧要,因为它不起作用)
.chatinp {
height: 10px;
width: 100%;
position: absolute;
overflow: hidden;
bottom: 0;
right: 0;
size: fixed;
height: auto;
border-top: solid;
}
#CHAT {
font-family: monospace;
font-size: 20px;
position: relative;
bottom: 0;
left: 0;
height: 100%;
width: 95%;
background: none;
border: solid 1px #fff;
padding: none;
margin: none;
}
#SEND {
font-family: monospace;
font-size: 20px;
position: relative;
bottom: 0;
right: 0;
height: 100%;
width: 10%;
background-color: #090;
border: solid 1px #fff;
padding: none;
margin: none;
}
<div class="chatinp">
<input type="text" name="CHAT" id="CHAT">
<button name="SEND", id="SEND">SEND</button>
</div>
解决方案
如果我了解您的需求,您可能需要使用弹性盒。
我添加display: flex
了父容器 ( .chatnip
) 和flex : <value>
子元素,以告诉他们应该占用多少空间。
盒子之间没有缝隙。
.chatinp {
height: 10px;
width: 100%;
position: absolute;
overflow: hidden;
bottom: 0;
right: 0;
size: fixed;
height: auto;
border-top: solid;
display: flex
}
#CHAT {
font-family: monospace;
font-size: 20px;
position: relative;
bottom: 0;
left: 0;
height: 100%;
background: none;
border: solid 1px #fff;
color: white;
flex: 9;
}
#SEND {
font-family: monospace;
font-size: 20px;
position: relative;
bottom: 0;
right: 0;
height: 100%;
background-color: #090;
border: solid 1px #fff;
color: white;
padding: none;
margin: none;
flex: 1;
}
<div class="chatinp">
<input type="text" name="CHAT" id="CHAT">
<button name="SEND", id="SEND">SEND</button>
</div>
推荐阅读
- python - 在表示从一个项目到另一个项目的相对距离的数据集上使用 K 均值聚类意味着什么?
- angular7 - 角料粘柱多于1列
- javascript - 在获取父元素的 id 时附加一个元素
- php - php通过自定义命令调用scrapy
- html - 找不到缺少的结束 div 标签
- mysql - 根据条件从表中检索结果
- django - Django,使用 sqlite 处理静态内容,使用 postgresql 处理其他所有内容
- c - 字符串中间的'\0'是否可以在C中被识别为字符串的结尾?
- java-8 - LinkedList .echo() 与 .peek() 的区别
- javascript - 我的脚本没有被调用或工作