5
<table  border="0" style="padding:10px;width: 960px;border-collapse: collapse;">

   <tbody>
<tr>
<td  style="padding: 0"><img src="8.jpg" alt="" /></td>
<td  style="padding: 0"><img src="98.jpg" alt="" /></td>
<td  style="padding: 0"><img src="998.jpg" alt="" /></td>
<td  style="padding: 0"><img src="1998.jpg" alt="" /></td>
</tr>
<tr>
<td  style="background-color: #757575;">11194</td>
<td  style="background-color: #757575;">11194</td>
<td  style="background-color: #757575;">11194</td>
<td  style="background-color: #757575;">11194</td>
</tr>
<tr>
<td  style="padding: 0"><img src="8.jpg" alt="" /></td>
<td  style="padding: 0"><img src="98.jpg" alt="" /></td>
<td  style="padding: 0"><img src="998.jpg" alt="" /></td>
<td  style="padding: 0"><img src="1998.jpg" alt="" /></td>
</tr>

</tbody>
</table>

why i can't add margin padding to the tr and td? i want the td (<td style="background-color: #757575;">11194</td>) have margin-right.namely, each separated by some space. but can't work. how to correct it. and the second tr have some space between the following tr.

user1932607
  • 75
  • 2
  • 2
  • 6
  • See my answer and provide the extra css if you have used rather than inline style on table. So i can see if some thing is missing in the question. – w3uiguru Dec 30 '12 at 07:01

4 Answers4

8

margin specifications are ignored for table cells Refer: http://www.w3.org/TR/CSS2/tables.html and CSS Cell Margin

Internal table elements generate rectangular boxes with content and borders. Cells have padding as well. Internal table elements do not have margins.

If you wanna add padding, just set border-collapse:separate refer: http://www.w3schools.com/cssref/playit.asp?filename=playcss_border-collapse

Community
  • 1
  • 1
macio.Jun
  • 9,647
  • 1
  • 45
  • 41
2

I guess you are asking for border-collapse; so try using it...

table {
   border-collapse: collapse;
}

If you want to add padding you can do it like

table.class_name td {
   padding: 0; 
}
Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
2

The reason because you are giving padding on table element and on td and you are giving padding:0

Remove border-collapse: collapse from table element and you can handle padding and margin easily in this table.

See the demo fiddle for concepts: http://jsfiddle.net/GVt3z/

Note: Above fiddle is not containing exact answer.

See updated fiddle for margin-right space but with different technique.

http://jsfiddle.net/GVt3z/1/

w3uiguru
  • 5,864
  • 2
  • 21
  • 25
  • could you have a try?althouth i set td (11194). those are all connect with each. both are not have space. – user1932607 Dec 30 '12 at 07:02
  • You can not give margin on td elements you can give padding to them, because they are all the childs of tr and tr is child element of table element. – w3uiguru Dec 30 '12 at 07:07
  • you can give margin on table elements and give padding to td elements. – w3uiguru Dec 30 '12 at 07:07
  • see my updated answer and see this fiddle after my answer http://jsfiddle.net/GVt3z/2/ . – w3uiguru Dec 30 '12 at 07:14
0

add "display:inline-block" to all elemans of table.

td{
  display:inline-block;
}
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 09 '22 at 21:18