Html 表格中没有空格的html图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3825500/
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 04:42:56  来源:igfitidea点击:

html images in table with no space

htmlcssimage

提问by bba

I have an html table in which I am placing images side by side inside the td's. How can I get it so that there is no space at all between each image? By default all browsers seem to put in a small space despite 0 padding and margin on each table element. I am not specifying a width on the td's so by default it takes up the width of the image inside of it.

我有一个 html 表,我将图像并排放置在 td 中。我怎样才能得到它,以便每个图像之间根本没有空间?默认情况下,尽管每个表格元素的填充和边距为 0,但所有浏览器似乎都放置在一个小空间中。我没有在 td 上指定宽度,因此默认情况下它会占用其中图像的宽度。

i.e:

IE:

<table>
  <tr>
    <td><img ... /></td> //no space between the td's
    <td><img ... /></td>
  </tr>
</table>

回答by Francis

One more thing that can avoid unwanted space between images:

可以避免图像之间不需要的空间的另一件事:

<td style="line-height:0;">

回答by Karel Petranek

Apply this css:

应用这个css:

td, tr, img  { padding: 0px; margin: 0px; border: none; }
table { border-collapse: collapse; }

This resets all spaces to 0.

这会将所有空格重置为 0。

回答by Vinay B R

cellspacing and cellpadding should be 0 on the table.

表格上的 cellpacing 和 cellpadding 应为 0。

<table cellspacing="0" cellpadding="0">
  <tr>
    <td><img></td> 
    <td><img></td>
  </tr>
</table>

回答by Jason McCreary

Take a look at cellpadding, border, and cellspacingattributes for the HTML tabletag. If you are using XHTML or CSS, then check out the corresponding styles - border-collapse, padding, etc.

看看cellpaddingbordercellspacing属性的HTMLtable标签。如果你正在使用XHTML或CSS,然后检查了相应的款式- border-collapsepadding等等。

回答by anov

On my situation, I am trying to continue coding photoshop / imageready splitted html (generated via slice tool or save for web).

在我的情况下,我正在尝试继续编码 photoshop/imageready 分割的 html(通过切片工具生成或保存为网络)。

If table have a "height" attribute and you replace some images with shorter content, table maintain height adding mysterios gaps between images.

如果 table 具有“height”属性并且您用较短的内容替换了一些图像,则 table 保持高度,在图像之间添加神秘的间隙。

All I have to remove the height. Simple and stupid, but this is a situation can happen.

所有我必须删除高度。简单而愚蠢,但这是可能发生的情况。