如何删除表中的行和列之间的不需要的空间?
如何删除表格中行和列之间的额外空间。
我试着改变表格和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>
将此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">
编辑(为了完整起见,我扩大了这5年后:):
Internet Explorer 6和Internet Explorer 7要求您直接将单元格间距设置为表格属性,否则间距不会消失。
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>
这对我有效:
#table {
border-collapse: collapse;
border-spacing: 0;
}
链接地址: http://www.djcxy.com/p/89239.html
上一篇: How to remove unwanted space between rows and columns in table?