Home » Html » HTML table needs spacing between columns, not rows

HTML table needs spacing between columns, not rows

Posted by: admin November 30, 2017 Leave a comment

Questions:

I have an HTML table.
I need to have spacing between the table columns, but not the table rows.

If I use the cellspacing css property it does it between both rows and columns. I also cannot use css in what I doing. I need to use pure html

Answers:

If you can use inline styling, you can set the left and right padding on each td.. Or you use an extra td between columns and set a number of non-breaking spaces as @rene kindly suggested.

http://jsfiddle.net/u5mN4/

http://jsfiddle.net/u5mN4/1/

Both are pretty ugly ;p css ftw

Questions:
Answers:

The better approach uses Shredder’s css rule: padding: 0 15px 0 15px
only instead of inline css, define a css rule that applies to all tds.
Do This by using a style tag in your page:

<style type="text/css">
td
{
    padding:0 15px 0 15px;
}
</style>

or give the table a class like “paddingBetweenCols” and in the site css use

.paddingBetweenCols td
{
    padding:0 15px 0 15px;
}

The site css approach defines a central rule that can be reused by all pages.

If your doing to use the site css approach, it would be best to define a class like above and apply the padding to the class…unless you want all td’s on the entire site to have the same rule applied.

Fiddle for using style tag

Fiddle for using site css

Note if you

Questions:
Answers:
<table cellpadding="pixels"cellspacing="pixels"></table>
<td align="position"valign="position"></td>

cellpadding=”length in pixels” ~ The cellpadding attribute, used in the <table> tag, specifies how much blank space to display in between the content of each table cell and its respective border. The value is defined as a length in pixels. Hence, a cellpadding="10" attribute-value pair will display 10 pixels of blank space on all four sides of the content of each cell in that table.

cellspacing=”length in pixels” ~ The cellspacing attribute, also used in the <table> tag, defines how much blank space to display in between adjacent table cells and in between table cells and the table border. The value is defined as a length in pixels. Hence, a cellspacing="10" attribute-value pair will horizontally and vertically separate all adjacent cells in the respective table by a length of 10 pixels. It will also offset all cells from the table’s frame on all four sides by a length of 10 pixels.