css - 增加文本框的大小
问题描述
我创建了一个表单并使用表格显示它。一个字段Full Name
应该很大,所以我使用colspan=2
了,但编辑器或输入框的大小没有增加,如下图所示。
到目前为止,这是我的代码。请帮我。
<tr>
<td>
<div class="form-group">
@Html.LabelFor(m => m.EmpID, htmlAttributes: new { @class = "control-label col-md-5 first" })
<div class="col-md-7">
@Html.EditorFor(model => model.EmpID, new { htmlAttributes = new { @class = "form-control", disabled = "disabled" } }) @Html.ValidationMessageFor(m => m.EmpID, "", new { @class = "text-danger" })
</div>
</div>
</td>
<td colspan="2">
<div class="form-group">
@Html.LabelFor(model => model.FullName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.FullName, new { htmlAttributes = new { @class = "form-control long-textbox", disabled = "disabled" } }) @Html.ValidationMessageFor(model => model.FullName, "", new { @class = "text-danger" })
</div>
</div>
</td>
</tr>
解决方案
您可以向标签(全名)和输入字段添加一个类,并指定每个元素应占用的宽度。
150px
在下面的示例中,标签和100% - 150px
输入字段的宽度设置为。使用该calc()
函数,您可以计算 CSS 中的值。
table {
width: 100%;
}
td {
border: 1px solid #ccc;
padding: 1rem;
}
/* specify how width the text label will be. */
label.full-width{
width: 150px;
}
/* specify the width of 100% - the width from the label */
input.full-width {
width: calc(100% - 150px);
float: right;
}
<table>
<tr>
<td>row 1 - col 1</td>
<td>row 1 - col 2</td>
</tr>
<tr>
<td colspan=2>
<label class="full-width">Full Name</label>
<input class="full-width">
</td>
</tr>
此外,在您的代码中,无需使用colspan=2
. 在我的示例中,我用它来说明如何使用它。在示例中,您使用一个单元格跨越/重叠两个列单元格。
推荐阅读
- javascript - Angular:何时将变量放在花括号内?
- c# - 如何在asp.net中检查用户类型
- go - 如何防止 Go 程序在意外 panic 后崩溃?
- heroku - Heroku PR App 无法连接到 GrapheneDB
- r - Q-learning R 的长度为零
- python - 使控制台消失并重新出现在启动时短暂显示
- java - python大整数乘法不计算最高有效数字
- javascript - 如何垂直显示数据标签?
- javascript - 如何在 OpenLayers 中销毁 ol.Geolocation 对象?
- javascript - 服务工作者不从缓存中返回文件