Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling Spacing Between Table Cells

I'm trying to create a table where each cell has a background color with white space between them. But I seem to be having trouble doing this.

I tried setting td margins but it seems to have no effect.

table.myclass td {     background-color: lime;     margin: 12px 12px 12px 12px; } 

If I do the same thing with padding, it works, but then I don't have the spacing between cells.

Could someone help me with this?

jsFiddle: http://jsfiddle.net/BfBSM/

like image 853
Jonathan Wood Avatar asked Sep 25 '12 14:09

Jonathan Wood


People also ask

How do you space between cells in a table?

Use the border-spacing property on the table element to set the spacing between cells. Make sure border-collapse is set to separate (or there will be a single border between each cell instead of a separate border around each one that can have spacing between them).

Which attribute of table helps you to control spacing between cells?

HTML | <table> cellspacing Attribute. The HTML <table> cellspacing Attribute is used to specify the space between the cells. The cellspacing attribute is set in terms of pixels.


1 Answers

Use the border-spacing property on the table element to set the spacing between cells.

Make sure border-collapse is set to separate (or there will be a single border between each cell instead of a separate border around each one that can have spacing between them).

like image 194
Quentin Avatar answered Sep 30 '22 11:09

Quentin