Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML table needs spacing between columns, not rows

Tags:

html

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.

like image 749
Nate Pet Avatar asked Aug 03 '12 18:08

Nate Pet


People also ask

How do I fix table spacing in HTML?

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).

How do you put space between table rows in HTML?

The space between two rows in a table can be done using CSS border-spacing and border-collapse property. The border-spacing property is used to set the spaces between cells of a table and border-collapse property is used to specify whether the border of table is collapse or not.

How do I fix columns and rows in HTML?

To freeze the row/column we can use a simple HTML table and CSS. HTML: In HTML we can define the header row by <th> tag or we can use <td> tag also. Below example is using the <th> tag. We also put the table in DIV element to see the horizontal and vertical scrollbar by setting the overflow property of the DIV element.


2 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;   } </style> 

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

.paddingBetweenCols td {   padding: 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

like image 172
user2258403 Avatar answered Sep 27 '22 18:09

user2258403


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

like image 45
Nick Rolando Avatar answered Sep 27 '22 18:09

Nick Rolando