Bootstrap 4 如何在不更改列宽的情况下将输入字段放在表标题上?
我使用Bootstrap表来显示包含许多不同大小列的列表。一切都很好,但我的客户要求在列的标题中包含一个输入字段。填充此字段后,将对列执行筛选 问题是插入输入字段会弄乱列宽。因此,由于文本面包线,现在每行的高度都更高 我需要输入字段的权重服从列大小,并且列宽保持不变,就好像输入字段不存在一样 原始代码大致类似于:Bootstrap 4 如何在不更改列宽的情况下将输入字段放在表标题上?,bootstrap-4,Bootstrap 4,我使用Bootstrap表来显示包含许多不同大小列的列表。一切都很好,但我的客户要求在列的标题中包含一个输入字段。填充此字段后,将对列执行筛选 问题是插入输入字段会弄乱列宽。因此,由于文本面包线,现在每行的高度都更高 我需要输入字段的权重服从列大小,并且列宽保持不变,就好像输入字段不存在一样 原始代码大致类似于: <!doctype html> <html lang="en"> <head> <!-- Required meta tags -
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<title>Test</title>
</head>
<body>
<div container>
<table class="table table-striped table-hover table-sm small">
<thead>
<tr>
<th>Project </th>
<th>Line </th>
<th>Code </th>
<th>Pay Item </th>
<th>Code </th>
<th>Material </th>
<th>Accept. </th>
<th>Test </th>
<th>Status </th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>10D276 </td>
<td>0020 </td>
<td>203.30 </td>
<td>EARTH BORROW </td>
<td>703.02</td>
<td>Earth Borrow</td>
<td>Test</td>
<td>AG-COMP-15</td>
<td>11</td>
<td>
<a href="# " class="zoom"><i class="material-icons" title="Show">zoom_in</i></a>
<a href="# " class="zoom"><i class="material-icons" title="Action">directions</i></a>
</td>
</tr>
<tr>
<td>10D276 </td>
<td>0510 </td>
<td>580.20 </td>
<td>RAPID SETTING CONCRETE REPAIR MATERIAL WITH COARSE AGGREGATE </td>
<td>780.04</td>
<td>Rapid Set Concrete Material with C. Agg</td>
<td>Appd</td>
<td>None_1</td>
<td>4</td>
<td>
<a href="#" class="zoom"><i class="material-icons" title="Show">zoom_in</i></a>
<a href="#" class="zoom"><i class="material-icons" title="Action">directions</i></a>
</td>
</tr>
</tbody>
</table>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
试验
项目
线
代码
付款项目
代码
材料
接受
试验
地位
行动
10D276
0020
203.30
借土
703.02
借土
试验
AG-COMP-15
11
10D276
0510
580.20
粗骨料快凝混凝土修补材料
780.04
含C.Agg的快速凝固混凝土材料
Appd
无(1)
4.
我刚刚将表放在表单中,并将输入字段放在标题中
<form>
<table class="table table-striped table-hover table-sm small">
<thead>
<tr>
<th>Project <input class="form-control form-control-sm" type="text" > </th>
<th>Line <input class="form-control form-control-sm" type="text" > </th>
<th>Code <input class="form-control form-control-sm" type="text" > </th>
<th>Pay Item <input class="form-control form-control-sm" type="text" > </th>
<th>Code <input class="form-control form-control-sm" type="text" > </th>
<th>Material <input class="form-control form-control-sm" type="text" > </th>
<th>Accept. <input class="form-control form-control-sm" type="text" > </th>
<th>Test <input class="form-control form-control-sm" type="text" > </th>
<th>Status <input class="form-control form-control-sm" type="text" > </th>
<th>Actions </th>
</tr>
项目
线
代码
付款项目
代码
材料
接受
试验
地位
行动
我在这里看到的最佳选择是使用css为列设置固定宽度值
<thead>
<tr>
<th style="width:5%;">Project <input class="form-control form-control-sm" type="text" > </th>
项目
这会将输入字段缩小到您可自定义的大小。我在这里看到的最佳选择是使用css为列设置固定宽度值
<thead>
<tr>
<th style="width:5%;">Project <input class="form-control form-control-sm" type="text" > </th>
项目
这会将输入字段缩小到您可自定义的大小。谢谢!最好是让Bootstrap根据表调整字段,而不是相反。我不喜欢在代码中留下固定百分比,但您的解决方案是有效的。我现在就这么做。谢谢你!最好是让Bootstrap根据表调整字段,而不是相反。我不喜欢在代码中留下固定百分比,但您的解决方案是有效的。我现在就做这个。