简体   繁体   English

如何删除 html 表格单元格中的所有左右填充?

[英]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 中相应的thtd标签,如下所示:

<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.

相关问题 在html表格单元格中,如何强制图像在左下角和右下角具有不同的高度? - In a html table cell, how can I force images to be the bottom left and the bottom right that have different heights? 如何删除 TimelineItem 上的左侧填充? - How can I remove left padding on TimelineItem? 如何对这个 HTML 表的定位进行排序? - 我需要右侧的提交按钮,需要删除左侧的间距 - How can I sort the positioning of this HTML Table? - I need the Submit button on the right hand side and need to remove the spacing on the left 如何删除div表格单元格中的垂直填充? - How do I remove the vertical padding in a div table-cell? HTML表格问题(固定的左单元格,右单元格填充了其余所有内容) - HTML table issue (fixed left cell, right cell filling all rest of the content) 如何在表格单元格(td)中定位元素,使得一个元素左对齐而另一个元素对齐? - How can I position elements within a table cell (td) such that one element is left aligned and the other right aligned? HTML表格单元格填充 - HTML Table Cell Padding 你能在HTML输入按钮上调整左右填充吗? - Can you tweak the left and right padding on an HTML input button? 如何删除子div中填充引起的表格单元格中无法解释的填充? - How to remove inexplicable padding in table cell caused by padding in child div? 如何强制 html 表的“td”元素中的单独元素显示内联(从左到右)? - How can I force separate elements within a “td” element of an html table to display inline (left to right)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM