简体   繁体   English

如何删除表格单元格之间的空格

[英]How to remove spaces between table cells

As you can see under 2nd row of my table between two cells there is a space which I want to remove but I am not sure how to achieve that.正如您在两个单元格之间的表格的第二行下看到的那样,有一个我想删除的空间,但我不知道如何实现这一点。

Any help or suggestion will appreciated.Thanks任何帮助或建议将不胜感激。谢谢

 var str1 = "78896541230"; str1 = str1.replace(/.(?=.{4})/g, 'x'); document.getElementById('output').innerHTML = str1;
 <table border="0" cellspacing="0" cellpadding="1" class="formtable"> <caption>Just for fun</caption> <tr> <td>The following will contain masked input number </td> <td id="output"></td> </tr> <tr> <td> If it is not masked number, then something is wrong.</td> </tr> </table>

<table border="0" cellspacing="0" cellpadding="1" class="formtable">
    <tr>
      <td>The following will contain masked input number </td>
      <td id="output">XXXXXXX0230</td>
    </tr>
    <tr>
      <td colspan="2"> If it is not masked number, then something is wrong.</td>
    </tr>
</table>

The white space between the text and the 'output' number is being caused by the longer text in the second row.文本和“输出”数字之间的空白是由第二行中较长的文本引起的。 This causes the first column of the first row stretch.这会导致第一行的第一列拉伸。 You're also nesting <tr> elements which you shouldn't.您还嵌套了不应嵌套的<tr>元素。

You could add a colspan="2" to the <td> in the second row.您可以将colspan="2"添加到第二行的<td>中。

You can use the cell spacing and cell padding attribute in html 5 And set their values to 0 or -1您可以使用 html 5 中的单元格间距和单元格填充属性,并将它们的值设置为 0 或 -1

The answer stated above is all good unless the text in second <td> element increases.I have found a better solution which does work in my case.除非第二个<td>元素中的文本增加,否则上述答案都很好。我找到了一个更好的解决方案,它确实适用于我的情况。 Instead of putting the value of #output in another <td> i can inline that in the previous <td> and that way the space won't be there.而不是将#output的值放在另一个<td>中,我可以将其内联在前一个<td>中,这样空间就不会存在。 Here's how就是这样

Code

 var str1 = "78896541230"; str1 = str1.replace(/.(?=.{4})/g, 'x'); document.getElementById('output').innerHTML = str1;
 <table border="0" cellspacing="0" cellpadding="1" class="formtable"> <caption>Just for fun</caption> <tr> <td>The following will contain masked input number <strong id="output"></strong></td> </tr> <tr> <td> If it is not masked number, then something is wrong.</td> </tr> </table>

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

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