Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use cellpadding and cellspacing on HTML5?

Tags:

html

css

Am trying to use CSS3 to set the cell-spacing and the cell-padding for my table since HTML5 doesn't support these attributes.

I have found many resources on the internet says that you should use border-spacing and padding using CSS.

Unfo. i tried all these tricks , but it seems that no thing changing at all. The spacing is very important because am including image structure on the different cell of the table.

So how i can solve it now ? plz need your help

#SearchTable
{
    border-collapse: collapse;
    padding:0px 0px 0px 0px;
}

#SearchTable td 
{
    padding:0;
    border-spacing:0px 0px; 
}
like image 879
Hatem Avatar asked Jan 21 '12 19:01

Hatem


People also ask

How do I use cellpadding and Cellspacing in HTML5?

Answer: Use the CSS padding & border-spacing property As we know the table's cellpadding and cellspacing attributes are removed in HTML5. But, you can still set padding inside the table cells easily using the CSS padding property. This is a valid way to produce the same effect as table's cellpadding attribute.

How do you add cellpadding and cellspacing in HTML?

Cell padding is the space between cell borders and the content within a cell. To set cell padding in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <table> tag, with the CSS property padding.

How do you do Cellspacing and cellpadding in a table?

You can easily set padding inside the table cells using the CSS padding property. It is a valid way to produce the same effect as the table's cellpadding attribute. Similarly, you can use the CSS border-spacing property to apply the spacing between adjacent table cell borders like the cellspacing attribute.

Why do we use cellpadding and cellspacing in HTML?

Cellpadding basically defines the space present between a table cell's border and the content present in it. Cellspacing basically defines the space present between individual adjacent cells. One can create it using the tag of HTML <table>, but it sets the type attribute to cellpadding.


3 Answers

For cellspacing:

  1. Set border-spacing on the table, not on the td.
  2. Set border-collapse to separate.
#SearchTable {
   border-collapse: separate;
   border-spacing: 8px; 
}
like image 172
Matt Parkins Avatar answered Nov 03 '22 08:11

Matt Parkins


You have not set id=SearchTable on the table, or you have some other stylesheet rules that override those that you specify. As such, the rules you posted are more than sufficient for the effect; you only need

#SearchTable
{
    border-collapse: collapse;
}

#SearchTable td 
{
    padding:0;
}

(which are already in CSS2).

like image 45
Jukka K. Korpela Avatar answered Nov 03 '22 08:11

Jukka K. Korpela


You need to set it like this. It worked for me.

#SearchTable {
    border-spacing:2px 2px;
    border-collapse:separate;
}

#SearchTable td {
    border:1px solid black;
}
like image 26
Binil Avatar answered Nov 03 '22 10:11

Binil