¿Cómo eliminar el espacio no deseado entre filas y columnas en la tabla?


¿Cómo elimino el espacio adicional entre las filas y columnas de la tabla?

He intentado cambiar el margen, el relleno y varias propiedades de borde en la tabla y tr y td.

Quiero que todas las imágenes estén una al lado de la otra para que parezcan una imagen grande.

¿Cómo debo arreglar esto?

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>
Author: Brian Tompsett - 汤莱恩, 2010-02-17

11 answers

Añade este reset CSS a tu código CSS: (Desde aquí)

/* 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;
}

Restablecerá el CSS de manera efectiva, eliminando el relleno y los márgenes.

 74
Author: vectran,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-06-13 02:24:38

Añadiendo a la respuesta de vectran: También tiene que establecer el atributo cellspacing en el elemento table para la compatibilidad entre navegadores.

<table cellspacing="0">

EDITAR (en aras de la integridad estoy ampliando esto 5 años después:):

Internet Explorer 6 y Internet Explorer 7 requiere que establezca cellspacing directamente como un atributo de tabla, de lo contrario el espacio no desaparecería.

Internet Explorer 8 y versiones posteriores y todas las demás versiones de los navegadores populares - Chrome, Firefox, Opera 4 + - soportan la propiedad CSS border-spacing.

Así que para hacer un reset de espaciado de celdas de tabla entre navegadores (compatible con IE6 como un navegador dinosaurio), puede seguir el siguiente ejemplo de código:

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>
 172
Author: easwee,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-02-25 22:54:35

Esto funcionó para mí:

#table {
  border-collapse: collapse;
  border-spacing: 0;
}
 61
Author: pagetribe,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-09-17 00:13:09

Para imágenes en td, use esto para imágenes:

display: block;

Que elimina el espacio no deseado para mí

 54
Author: Jacob Bertelsen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-01-02 13:54:57
table 
{
    border-collapse: collapse;
}

Colapsará todos los bordes que separan las columnas de la tabla...

O intenta

<table cellspacing="0" style="border-spacing: 0;">

Haga todo el espaciado de celdas a 0 y el espaciado de bordes 0 para lograr lo mismo.

Diviértete!

 8
Author: Aamir Shahzad,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-05-21 16:41:07

Simplemente añadiendo encima de la respuesta de Jacob, para img en td,

body {line-height: 0;}
img {display: block; vertical-align: bottom;}

Esto funciona para la mayoría de los clientes de correo electrónico, incluido Gmail. Pero no Outlook. Para Outlook, debe hacer dos pasos más:

table {border-collapse: collapse;}

Y establece que cada elemento td tenga el mismo height y width que sus imágenes contenidas. Por ejemplo,

<td width="600" height="80" style="line-height: 80px;">
    <img height="80" src="http://www.website.com/images/Nature_01.jpg" width="600" />
</td>
 7
Author: hexinpeter,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-06-26 04:37:14

Para HTML5 compatible con los estándares, agregue todo este css para eliminar todo el espacio entre las imágenes en las tablas:

table { 
    border-spacing: 0;
    border-collapse: collapse;
}
td {
    padding:0px;
}
td img {
    display:block;
}
 6
Author: totallytotallyamazing,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-05-21 20:47:27

Establecer Cellpadding y cellspacing en 0 eliminará el espacio innecesario entre filas y columnas...

 4
Author: Vijay,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-02-17 09:19:11

Prueba esto,

table{
border-collapse: collapse; /* 'cellspacing' equivalent */
}

table td, 
table th{
padding: 0; /* 'cellpadding' equivalent */
}
 3
Author: Rakesh Vadnal,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-12-27 12:26:41

Agregar esta línea al principio del archivo s funcionó para mí:

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

Modificar el css para establecer las propiedades de borde adecuadas no funcionó hasta que agregué la línea anterior

 2
Author: Albert s,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-20 17:15:28

¿Ha intentado eliminar los TRs que tienen un colspan y ver si cambia algo?

He experimentado que los colspans y los rowspans son bastante desagradables cuando se trata de diseños de mesas precisos. Si sus imágenes se ven bien sin el colspan-TRs, me gustaría empezar desde allí y construir un conjunto de tablas anidadas.

También tu estilo.css no parece estar completo, tal vez hay algo mal allí? Al menos añadiría padding: 0; margin: 0; a la tabla (o a la clase "mytable"). Asegúrese, sus imágenes no tiene espacios y / o bordes, también (por ejemplo, agregando img { border: 0; } a su hoja de estilo).

 0
Author: Select0r,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-02-17 09:12:29