[英]How can I remove all left and right padding in an html table cell?
I am creating a timeline, with a column for each year represented in the timeline;我正在创建一个时间线,在时间线中代表每一年的一列; I want these year columns to be as "skinny" (unwide) as possible.
我希望这些年份列尽可能地“细”(不宽)。 Right now they look like so:
现在它们看起来像这样:
How can I remove all the left and right padding within the cells between the years?如何删除年份之间单元格内的所有左右填充?
My current code is:我目前的代码是:
<table class="table table-sm table-bordered">
<thead class="thead-dark">
<tr>
<th scope="col">NAME</th>
<th scope="col">RELATIONSHIP</th>
<th scope="col">1794</th>
<th scope="col">1795</th>
<th scope="col">1796</th>
NOTE: I also want the rows to refrain from wrapping.注意:我还希望行避免换行。 The rows code is currently:
行代码目前是:
<tr>
<th scope="row">John Marshall Clemens</th>
<td>Father</td>
<td>~</td>
<td>~</td>
<td>~</td>
You can use it like this你可以像这样使用它
<table cellpadding = "0">
<tr>
<th> Month </th>
<th> Savings </th>
</tr>
<tr>
<td> January </td>
<td> $100 </td>
</tr>
</table>
As you are using bootstrap you can remove any padding and margins with bootstrap spacing helper classes当您使用引导程序时,您可以使用引导程序间距助手类删除任何填充和边距
It has a very flexible syntax to adding or removing paddings and margings.它具有非常灵活的语法来添加或删除填充和边距。 In your case you need to ad
px-0
class to your corsponding th
and td
tags in head and body like bellow:在您的情况下,您需要将
px-0
类添加到 head 和 body 中相应的th
和td
标签,如下所示:
<table class="table table-bordered text-center">
<thead>
<tr>
<th>Name</th>
<th>Relation</th>
<th class="px-0">1794</th>
<th class="px-0">1795</th>
<th class="px-0">1796</th>
<th class="px-0">1797</th>
</tr>
</thead>
<tbody>
<tr>
<td>jhon</td>
<td>fater</td>
<td class="px-0">~</td>
<td class="px-0">~</td>
<td class="px-0">~</td>
<td class="px-0">~</td>
</tr>
<tr>
<td>mark</td>
<td>self</td>
<td class="px-0">~</td>
<td class="px-0">~</td>
<td class="px-0">~</td>
<td class="px-0">~</td>
</tr>
<tr>
<td>livy</td>
<td>wife</td>
<td class="px-0">~</td>
<td class="px-0">~</td>
<td class="px-0">~</td>
<td class="px-0">~</td>
</tr>
</tbody>
</table>
px-0
is equal to px-0
等于
.px-0 {
padding-right: 0 !important;
padding-left: 0 !important;
}
if you are using bootstrap then bootstrap itself provide padding of 12px with <td>
and <th>
.如果您使用的是引导程序,那么引导程序本身会使用
<td>
和<th>
提供 12px 的填充。 so for making table "skinny" you need to override css.所以为了使表格“瘦”,你需要覆盖 css。
html html
<table class="table table-bordered text-center">
<thead>
<tr>
<th>Name</th>
<th>Relation</th>
<th>1794</th>
<th>1795</th>
<th>1796</th>
<th>1797</th>
</tr>
</thead>
<tbody>
<tr>
<td>jhon</td>
<td>fater</td>
<td>~</td>
<td>~</td>
<td>~</td>
<td>~</td>
</tr>
<tr>
<td>mark</td>
<td>self</td>
<td>~</td>
<td>~</td>
<td>~</td>
<td>~</td>
</tr>
<tr>
<td>livy</td>
<td>wife</td>
<td>~</td>
<td>~</td>
<td>~</td>
<td>~</td>
</tr>
</tbody>
</table>
css css
th, td {
padding: 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.