简体   繁体   English

添加链接后表中的多余空间

[英]Extra space in table after adding link

A while ago I had a problem where an image in a table was not filling the cell, which was covered in this post 前一段时间我曾在那里的表中的形象,不是填充单元的问题,这是覆盖在这个岗位

However, I now have an edit for this, I need to add links to the image and text. 但是,我现在对此进行了编辑,我需要向图像和文本添加链接。 And again, I get the same problem, I've got excess whitespace. 再一次,我遇到同样的问题,我有多余的空格。

<table>
    <tr>
        <td width="200px" height="175px"  style="text-align: center; border: 0; background-color: #ffffff; padding: 0; margin: 0; border-collapse: collapse; "> 
            <a href="http://www.placekitten.com/"><img src="http://www.placekitten.com/200/175" style="display: block; padding: 0; border: 0;" /></a>
        </td>
    </tr>
    <tr>
        <td width="200px" height="25px"  style="text-align: center; border: 0; background-color: #535152; color: #fffdfe; padding: 0; margin: 0; border-collapse: collapse; ">
            <a href="http://www.placekitten.com/">Text</a>
        </td>
    </tr>
</table>

Here is a JSFiddle 这是一个JSFiddle

Is it a case of padding somewhere? 是在某处填充的情况吗? Or what? 要不然是啥?

Add the below CSS: 添加以下CSS:

Demo Fiddle 演示小提琴

table{
    border-collapse:collapse;
}

You should also move your styles out of being inline, into a stylesheet. 您还应该将样式从内联方式移到样式表中。

More on border-collapse from MDN 有关MDN的border-collapse更多信息

The border-collapse CSS property selects a table's border model. border-collapse CSS属性选择表格的边框模型。 This has a big influence on the look and style of the table cells. 这对表格单元格的外观和样式有很大影响。

The separated model is the traditional HTML table border model. 分离的模型是传统的HTML表边框模型。 Adjacent cells each have their own distinct borders. 每个相邻的单元格都有各自不同的边界。 The distance between them given by the border-spacing property. 它们之间的距离由border-spacing属性给出。

In the collapsed border model, adjacent table cells share borders. 在折叠的边框模型中,相邻的表格单元格共享边框。 In that model, the border-style value of inset behaves like groove, and outset behaves like ridge. 在该模型中,inset的边框样式值的行为类似于沟槽,而outset的行为类似于脊。

You should move or add border-collapse:collapse to your table instead of your td. 您应该将border-collapse:collapse移动或添加到表中,而不是td。

border-collapse is a table property not td 's. border-collapse是一个table属性,而不是td的属性。

and more info: border-collapse 及更多信息: border-collapse

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM