html - 在内容框中输入带有标签的剩余宽度
问题描述
我在自定义内容框的样式方面遇到了一些问题。内容框包含几个label
和input
字段。内容框有一个width
`500px。
其中一些labels
比其他的长,但是输入应该总是和窗口一样大(- 一点空白)。
这是我现在拥有的 HTML:
<div class="content">
<div class="row">
<label for="test1">This is a test #1</label>
<input type="text" name="test1">
</div>
<div class="row">
<label for="test2">This is a test #2</label>
<input type="text" name="test2">
</div>
<div class="row">
<label for="test3">But this is a test with a much longer label</label>
<input type="text" name="test3">
</div>
</div>
这是CSS:
.content {
border: 1px solid #000;
width: 500px;
height: 500px;
}
.row {
margin-top: 5px;
}
input {
width: 385px;
}
正如这里的小提琴所示:https ://jsfiddle.net/4ga3533o/你可以看到前 2 个'rows'
工作正常,但是到第三个,因为宽度比内容框长,我怎么input
能label
让它工作,这样标签可以有不同的长度,但宽度只占用宽度的剩余空间?
解决方案
你可以flex
.content {
border: 1px solid #000;
width: 500px;
height: 500px;
}
.row {
margin-top: 5px;
display: flex;
}
input {
flex: 1;
}
label {
margin-right: 10px;
}
<div class="content">
<div class="row">
<label for="test1">This is a test #1</label>
<input type="text" name="test1">
</div>
<div class="row">
<label for="test2">This is a test #2</label>
<input type="text" name="test2">
</div>
<div class="row">
<label for="test3">But this is a test with a much longer label</label>
<input type="text" name="test3">
</div>
</div>
推荐阅读
- c# - 在 asp.net core 中基于语言环境的时间格式
- c# - c# Filewatcher Microsoft Word
- c# - 在 Linq 中选择包含其他对象列表的新对象
- javascript - .toFixed 函数不适用于 js-object
- c# - 使用管理员权限和权限从 C# 执行 Powershell 脚本
- python - 在 python 中从 JSON 字典中搜索并获取值
- ios - UITextView 中的文本更改事件
- sqlite - 查询运行了几天
- scikit-learn - 如何从应用于多类问题的 LogisticRegressionCV 的输出中选择 C
- python - 无法在 Django 中导入名称“登录”