【发布时间】:2019-05-29 16:01:27
【问题描述】:
我从 Bootstrap 复制了表格代码并将每一行设置为具有自己的背景颜色,但每个 1 之间都有空白,我不知道为什么。
我将所有“tr”、“tbody”和“thead”的边框、边距和填充设置为 0。
问题:如何防止表格单元格周围出现空白?
#C1{
margin-top: 40px;
width: 75%;
border: 1px solid black;
padding: 0px;
}
.table-red{
background-color: red;
color: #ffffff
}
.table{
margin-bottom: 0px;
padding: 0px;
}
.table-striped tbody tr:nth-of-type(even){
background-color: red;
color: white;
}
.table-striped tbody tr:nth-of-type(odd){
background-color: blue;
color: white;
border: 0;
}
thead{
background-color: green;
border: 0px;
margin-bottom: 0px;
margin-top: 0px;
}
th{
border: 0px;
}
tbody{
margin-top: 0px;
}
<div class="container" id="C1">
<table class="table table-striped">
<thead >
<tr>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Larry</td>
<td>the Bird</td>
<td>@twitter</td>
</tr>
</tbody>
</table>
</div>
空白应该消失
【问题讨论】: