我有一个问题要问你。我正在尝试在容器流体 div中固定表格列的大小。我尝试设置 style="width: xx.x%"
,但是它会根据单元格内容而继续更改。
我也尝试过使用max-with,但是它仍然无法正常工作。在我的代码下面:
<div class="container-fluid">
<div class="row">
<div class="col-12">
<table class="table table-sm text-nowrap">
<thead>
<tr class="bg-info text-white">
<th style="max-width: 1%">2020</th>
<th style="max-width: 9%">Voci</th>
<th class="text-center" style="max-width: 7.5%">Gen</th>
<th class="text-center" style="max-width: 7.5%">Feb</th>
.......
我希望该列具有固定宽度(例如,最大值和最小值等于7.5%)。 我怎么能在引导程序中得到这个?
答案 0 :(得分:1)
您应该为d-flex
使用table
属性,以便制作fix width
。
您可以使用col
类来指定每列的宽度。
<!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://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-12">
<table id="productSizes" class="table">
<thead>
<tr class="bg-info d-flex">
<th class="col-3">2020</th>
<th class="col-3">Voice</th>
<th class="col-3">Gen</th>
<th class="col-3">Feb</th>
</tr>
</thead>
<tbody>
<tr class="d-flex">
<td class="col-3">First Column with fixed width look at that, it is moving text to next line if it
overflowing</td>
<td class="col-3">Second Column with fixed width</td>
<td class="col-3">Lorem ipsum dolor sit amet consectetur adipisicing elit. Expedita, atque earum
asperiores ex
quod quia mollitia dese</td>
<td class="col-3">This is third clumn</td>
</tr>
<tr class="d-flex">
<td class="col-3">8</td>
<td class="col-3">84 - 86</td>
<td class="col-3">66 - 68</td>
<td class="col-3">94 - 96</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>