-1

I can't figure it out, why is this table 102px and not 100px in height? Is there another css attribute I need to set otherthan:

table {
    border-spacing:0;
    border-collapse:collapse;
}

example: https://jsfiddle.net/0enwstw7/2/

user81993
  • 6,167
  • 6
  • 32
  • 64

5 Answers5

1

There appears to be padding on the <td> tag assigned by default. This should fix it:

td {
    padding: 0;
}
Matt Dalzell
  • 775
  • 3
  • 14
0

The <td> element defaults to having 1px padding, which adds a pixel on each side to make 102px total.

Remove it with td{padding:0;}

Spudley
  • 166,037
  • 39
  • 233
  • 307
0

It's the padding of the td that adds another 2px;

You have set the up div to be 100px but you are measuring the table.

You can set the padding of the td to 0;

td  {
padding: 0px;
}
xuma202
  • 1,074
  • 1
  • 10
  • 22
0

Try removing implicit td padding which is included into overall size of the table. Sufficed to add some directive like this:

td {
    padding: 0;
}

see: https://jsfiddle.net/0enwstw7/3/

helvete
  • 2,455
  • 13
  • 33
  • 37
0

Take a look at this.

enter image description here

Your browser (e.g. Chrome) has its own stylesheet and that's why it adds that border-spacing: 2px; to the table.

If you want more information about browser specific stylesheet, take a look at here.

And Yes. Like lots of people here already mentioned it, you can override the setting by adding

td {
  padding: 0px;
}

BUT I still think it's important to know WHY this happened.

Hope this helps.

Community
  • 1
  • 1
Saehun Sean Oh
  • 2,103
  • 1
  • 21
  • 41