Jack
Jack

Reputation: 3494

Why is <td></td><td></td> not the same as <td colspan="2"></td>

I am replacing multiple TDs with a single TD and a colspan attribute.

However this renders completely differently.

I cannot see why <td></td><td></td> is different to <td colspan="2"></td>

My issue is that the sum of the width of the first 2 TDs is not the same as the width of the colspanned TD. So my cells dont line up.

This happens in IE, FF and Safari.

BONUS QUESTION: Is there any style etc I can apply to ensure the width of the colspan column is equal to the sum of the width of the other TDs being replaced?

Why am I doing this? I am trying to reduce the amount of HTML being generated by DevExpress XtraReports which uses thousands of tiny TDs to position elements. It bloats the HTML many times over, so I am capturing the HTML before it gets sent to the browser and doing some rudimentary search/replace. It's a hack, I know.

Upvotes: 4

Views: 267

Answers (4)

Adam
Adam

Reputation: 723

Post your code. Otherwise it could be anything. But super easy stuff below works.

This will create a table with two rows. First row has 3 columns. Second row has 2 columns, the first taking up two columns.

<table border="1">
<tr>
<td>Something</td>
<td>Something</td>
<td>Something</td>
</tr>
<tr>
<td colspan=2>Something2</td>
<td>Something</td>
</tr>
</table>

Upvotes: 1

Michael C. Gates
Michael C. Gates

Reputation: 992

You have to set their width with styles. That's pretty much the only way. But then, you might as well just use DIV's with width specified. More control.

Tables are meant for data. I used to be a table-freak. Once I got the hang of CSS for layout, I rarely use tables, unless I WANT the width's to change. That's the cool thing about tables--they will fill out nicely based on the data.

I have never seen display any wider or narrower than the above/below . Unless there's an error in your code. Post it, and we'll see what we can do. What exactly are you trying to achieve by all this?

Upvotes: 0

Stefan Kendall
Stefan Kendall

Reputation: 67812

The first example will have two sets of margins, padding, css rules, etc. The second will have only one set of rules applied, but applied to an element which fits in two columns.

Upvotes: 7

tjg184
tjg184

Reputation: 4676

I could certainly see where the multiple tds would render differently because of column spacing. One way to verify this is to force a border on the table (e.g. ). This should lead you in some direction.

Upvotes: 0

Related Questions