我如何删除表中的行和列之间的额外空间。

我已经尝试改变边缘,填充,和各种边界属性的表和tr和td。

我希望所有的图片都是紧挨着的,看起来像一个大图像。

我该如何解决这个问题?

CSS

table {
  border-collapse: collapse;
}

HTML

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
  <title>Tera Byte Video Game Creation Camp</title>
  <link rel="stylesheet" type="text/css" href="style.css"></link>
</head>

<body>
  <table class="mytable" align="center">
    <tr class="header">
      <td colspan="3"><img src="images/home_01.png" /></td>
    </tr>
    <tr class="top">
      <td colspan="3"><img src="images/home_02.png" /></td>
    </tr>
    <tr class="link-row">
      <td><img src="images/home_03.png" /></td>
      <td><img src="images/home_04.png" /></td>
      <td><img src="images/home_05.png" /></td>
    </tr>
    <tr class="link-row">
      <td><img src="images/home_07.png" /></td>
      <td><img src="images/home_06.png" /></td>
      <td><img src="images/home_08.png" /></td>
    </tr>
    <tr class="link-row">
      <td><img src="images/home_09.png" /></td>
      <td><img src="images/home_10.png" /></td>
      <td><img src="images/home_11.png" /></td>
    </tr>
    <tr class="link-row">
      <td><img src="images/home_12.png" /></td>
      <td><img src="images/home_13.png" /></td>
      <td><img src="images/home_14.png" /></td>
    </tr>
    <tr class="bottom">
      <td colspan="3"><img src="images/home_15.png" /></td>
    </tr>
  </table>

</body>

</html>

当前回答

对于符合标准的HTML5,添加所有这些css来删除表格中图像之间的所有空间:

table { 
    border-spacing: 0;
    border-collapse: collapse;
}
td {
    padding:0px;
}
td img {
    display:block;
}

其他回答

table{ border: 1px solid black; } table td { border: 1px solid black; /* Style just to show the table cell boundaries */ } table.no-spacing { border-spacing:0; /* Removes the cell spacing via CSS */ border-collapse: collapse; /* Optional - if you don't want to have double border where cells touch */ } <p>Default table:</p> <table> <tr> <td>First cell</td> <td>Second cell</td> </tr> </table> <p>Removed spacing:</p> <table class="no-spacing" cellspacing="0"> <!-- cellspacing 0 to support IE6 and IE7 --> <tr> <td>First cell</td> <td>Second cell</td> </tr> </table>

在文件开头添加这一行对我来说很有效:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

修改CSS以设置适当的边界属性并没有起作用,直到我添加了上面的行

我只需要加上一句:

line-height: 0px;

在我

<tr ...>

将这个CSS重置添加到你的CSS代码中:(从这里)

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

它将有效地重置CSS,消除填充和边距。

添加到vectran的答案:为了跨浏览器兼容性,您还必须在表元素上设置cellspacing属性。

<table cellspacing="0">

EDIT(为了完整起见,我将在5年后展开:):

Internet Explorer 6和Internet Explorer 7要求您直接将cellspacing设置为表属性,否则空格不会消失。

Internet Explorer 8及更高版本以及所有其他流行浏览器(Chrome、Firefox、Opera 4+)都支持CSS属性border-spacing。

所以为了重置跨浏览器的表格单元格间距(支持IE6作为恐龙浏览器),你可以遵循下面的代码示例:

table{ border: 1px solid black; } table td { border: 1px solid black; /* Style just to show the table cell boundaries */ } table.no-spacing { border-spacing:0; /* Removes the cell spacing via CSS */ border-collapse: collapse; /* Optional - if you don't want to have double border where cells touch */ } <p>Default table:</p> <table> <tr> <td>First cell</td> <td>Second cell</td> </tr> </table> <p>Removed spacing:</p> <table class="no-spacing" cellspacing="0"> <!-- cellspacing 0 to support IE6 and IE7 --> <tr> <td>First cell</td> <td>Second cell</td> </tr> </table>