如何删除 HTML 表中行之间的分隔?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2949992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:17:21  来源:igfitidea点击:

How do I remove separation between rows in a HTML table?

htmlimagehtml-tablemarginpadding

提问by Roman

I have a html table with 3 rows and 1 column. In the top and button row I have images and in the middle row I have div.

我有一个 3 行 1 列的 html 表。在顶部和按钮行中,我有图像,在中间行中,我有 div。

Between my rows I see a separation (I see background of my page). I tried to set all padding and margins to zero (for tables, div and images) and I still have this separation. Can anybody, please, help me to solve this problem.

在我的行之间,我看到了一个分隔(我看到了我的页面的背景)。我尝试将所有填充和边距设置为零(对于表格、div 和图像),但我仍然有这种分隔。任何人都可以请帮我解决这个问题。

采纳答案by Paul

Set the cellspacing=0in the <table>tag as well as cellpadding=0.

cellspacing=0<table>标签中设置以及cellpadding=0

回答by gonzohunter

Try using 'border-collapse':

尝试使用“边框折叠”:

table {
  border-collapse: collapse;
}

回答by Amin Saqi

Use this in img tag :

在 img 标签中使用它:

display: block;

回答by Rerum Fontis

Gonzohunter nailed this, alright, but you may find it easier to just set the style on the table, assuming you are in a recent HTML version.

Gonzohunter 解决了这个问题,好吧,但您可能会发现在表格上设置样式更容易,假设您使用的是最新的 HTML 版本。

I used

我用了

<table style='border-collapse: collapse;'>
    ... 
</table>

This worked perfectly.

这工作得很好。

回答by Gert Grenander

It seems that it's your H2 that's causing it. To fix it, set the top margin of it to zero:

似乎是你的 H2 导致了它。要修复它,请将其顶部边距设置为零:

<h2 style="margin-top: 0;"><span class="text">Welcome to the Colored Trails Game Page!</span></h2>

回答by Dolph

You need to eliminate spacing from the table cells themselves.

您需要消除表格单元格本身的间距。

In CSS:

在 CSS 中:

<style type="text/css">
  td {
    border-collapse: collapse;
    border-spacing: 0;
    margin: 0;
    padding: 0;
  }
</style>

Or in HTML 4.01/XHTML 1.0 DTD (Strict or Transitional):

或者在HTML 4.01/XHTML 1.0 DTD(严格或过渡)中

<table cellspacing="0" cellpadding="0">
  [...]
</table>