Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't get table's cells fitting tightly 2

Status
Not open for further replies.

jsteph

Technical User
Oct 24, 2002
2,562
US
Hi all,
I'm generating an html table and I want to have it look identical to an Excel spreadsheet (the standard default that opens when you open a blank).

But the html table always has space between the borders of the td's and the rows. I've set all the Padding and Marginto 0px, and I have the borders at 1px, but there are still several pixels between each border on all sides.

What do I need to do to get the stylesheet to make the table the way I define it? I am deleting temp internet files to make sure the css is removed and a new one loaded as I test.
Thanks,
--Jim
 
Have you set the cellspacing and cellpadding properties of the table to 0 as well?

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
If I try "cellspacing" and "cellpadding" Visual Studio gives an error saying it's not a known css property.

However, I am using padding, border, and margin. I even specified the full -left, -top, etc. to be sure. Here's an example:
Code:
	padding-top: 0px;
	padding-bottom: 0px;
	padding-left: 0px;
	padding-right: 0px;	
	margin-top: 0px;
	margin-bottom: 0px;
	margin-left: 0px;
	margin-right: 0px;
	border-top: 0px;
	border-bottom: 0px;
	border-left: 0px;
	border-right: 0px;
	border-width: 0px;
The <td>,<tr>,<table> and <input> all have the above settings, the exception being the input which is inside the td, which has a border of 1px. But the spacing between these borders is at least 3 px all around.
--Jim
 
You need to add border-collapse: collapse; to your table. That will instruct it to join the borders of adjacent cells into one -- which in turn will give you the result you're asking for.

You could achieve the same by adding cellspacing="0" attribute to your table tag.

[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
If I try "cellspacing" and "cellpadding" Visual Studio gives an error saying it's not a known css property.

That's because they aren't... they are attributes of the table element.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hi

Jim said:
there are still several pixels between each border on all sides
The exact solution for that would be :
CSS:
table [teal]{[/teal]
  [blue]border-spacing:[/blue] [green]0[/green];
[teal]}[/teal]
( CSS 2.1 | Tables | Borders | The separated borders model )

But while Explorer supports it only since version 8, people used to use [tt]border-collapse[/tt] instead as Vragabond mentioned.

Feherke.
 
vragabond, feherke,
Perfect! That was the golden ticket, I'm good to go!
--Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top