简体   繁体   English

html中的表间距

[英]Table spacing in html

For what ever reason, I get a small gap in between the two TD cells (Lines dont touch). 出于某种原因,我在两个TD单元之间得到了一个小的间隙(线不接触)。 There is no padding or margin on that side... I did this collapsing idea. 那边没有填充物或边缘......我做了这个崩溃的想法。

Why is it there? 为什么会这样? http://jsfiddle.net/CKy6U/ http://jsfiddle.net/CKy6U/

My html: 我的HTML:

<table>
    <tr>
        <td>
            TEST CELL 1
        </td>
         <td>
             TEST CELL 2
        </td>
    </tr>
</table>

my CSS: 我的CSS:

table
{
    width: 100%;
}
tr
{
    border-bottom: 1px solid Black;
}

td
{
    border-collapse: separate;
    border-spacing: 0px;
    border-left: 1px solid Black;
    border-bottom: 1px solid Black;
    padding: 3px;
    width: 50%;
}

My Result: 我的结果: 在此输入图像描述

Add Border Collapse for table. 为表添加边框折叠。

table
{
width: 100%;
border-collapse:collapse;
}

DEMO DEMO

You have to add border-collapse: collapse in your table or cellspacing="0" in your html table. 您必须在table添加border-collapse: collapse或在html表格中添加cellspacing="0"

css CSS

table {
  width: 100%;
  border-collapse: collapse;
}

fiddle 小提琴

html: HTML:

<table cellspacing="0">

fiddle 小提琴

Both solutions should work. 这两种方案都应该有效 But use border-colapse cause as @Mooseman comment cellspacing is obsolete in html5. 但是使用border-colapse导致@Mooseman注释cellspacing在html5中已经过时了。

Add border-right: 0px; 添加border-right: 0px; to and remove border-collapse: separate from the td . to和remove border-collapse: separate td border-collapse: separate Add border-collapse: collapse to the table . 添加border-collapse: collapsetable

Fiddle: http://jsfiddle.net/CKy6U/7/ 小提琴: http//jsfiddle.net/CKy6U/7/

Try like this: LINK 试试这样: LINK

CSS: CSS:

 table {
        width: 100%;
        border-collapse:collapse;
    }

使用normalize.csscss reset我也会添加

<table cellspacing="0" cellpadding="0"> ... </table>

Remove the border-collapse on the td and add it to the table 删除td上的border-collapse并将其添加到table

table{
    width: 100%;
    border-collapse: collapse;
}

tr{
    border-bottom: 1px solid black;
}

td{
    border-spacing: 0px;
    border-left: 1px solid black;
    border-bottom: 1px solid black;
    padding: 3px;
    width: 50%;
}

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

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