如何限制引导表的每一列的宽度?
我试着四处游荡,但似乎无法缩小专栏。
https://plnkr.co/edit/XhwIUynVgAxMBpJo8x8N?p=preview
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link data-require="[email protected]" data-semver="3.2.0" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Table</h2>
<p>The .table class adds basic styling (light padding and only horizontal dividers) to a table:</p>
<table class="table">
<thead>
<tr>
<th>#</th>
<th style="width:20px">Firstname</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Anna</td>
</tr>
<tr>
<td>2</td>
<td>Debbie</td>
</tr>
<tr>
<td>3</td>
<td>John</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
最佳答案
您可以设置table-layout: fixed
并设置列的静态宽度。
.table {
table-layout:fixed;
}
td, th {
width: 90px;
}
Demo
.table {
table-layout:fixed;
}
td, th {
width: 90px;
border: 1px solid black;
text-align: left;
}
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Firstname</th>
<th>Lastname</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Anna</td>
<td>Lastname</td>
</tr>
<tr>
<td>2</td>
<td>Debbie</td>
<td>Lastname</td>
</tr>
<tr>
<td>3</td>
<td>John</td>
<td>Lastname</td>
</tr>
</tbody>
</table>
关于html - CSS引导表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35468988/