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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<td> and </td> must be in the same line ????

Status
Not open for further replies.

susan17

Programmer
Nov 6, 2001
12
0
0
SG
Hi!

Is the open <td> tag and the closing </td> tag needs to be in the same line?

I tried these 2 blocks of codes and the result if different.
1.
<table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; border=&quot;0&quot; width=&quot;443&quot;>
<tr>
<td bgcolor=&quot;#006699&quot;><img alt=&quot;&quot; height=&quot;1&quot; width=&quot;1&quot; src=&quot;</tr>
</table>

The image displayed is of correct height (i.e. very thin, since height=1).

2.
<table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; border=&quot;0&quot; width=&quot;443&quot;>
<tr>
<td bgcolor=&quot;#006699&quot;><img alt=&quot;&quot; height=&quot;1&quot; width=&quot;1&quot; src=&quot;</td>
</tr>
</table>

The image displayed is of wrong height (thicker).

Is this as expected?
This is not documented in W3C's website

Anyone have any idea? or any references to confirm this?

Thanks.
Susan
 
No, opening <td> and the closing </td> tags do NOT have to be in the same line.

However, it is recomended to place closing </td> tag on the same line (and without whitespaces) with the last tag of table cell content. Otherwise there'll be extra space in this cell.

In your case it looks like the image displayed is of wrong height. This is not true: the image dimentions are as defined in <img> tag, but there's an extra whitespace after it.

 
Ok.. I also think that it's not supposed to behave that way, however can anyone explain why this is so, and how to go about it?

Cos in 1 page there can be many <td> and </td> tags and changing them to be in 1 line is really time consuming.

Anyone have any idea?
 
Hello Susan,
in fact, i´ve been working with html and let me tell you that there are some thing in this language that aren't totally linear.
The case you're refering to isn't propperly what i could say &quot;not linear&quot;. Placing the closing tag </td> in the next line is an option, and the result must be the same as if it was in the same line.
About the image size, well, as Starway said, it's defined on the <img src > tag but be carefull, that is not all of it.
Most of the times, when you have a more_then_one_line table, the image can be expanded(and so, the width or height is not what you defined) to fill the row (tr)or the td (just to be in line with the other rows).
So, the best way to see what's hapening is to place the table's border to 1 and check the diferences.Probably, it's a not_defined_width_or_height_cell that html sometimes expands to a value and someother to another value.

====================
* Marta Oliveira *
====================
marta100@aeiou.pt
====================
CPC-TA Braga
====================
Portugal
====================

 
Susan,
When you type your code in text editor and hit [Enter] this always creates an extra whitespace, but you commonly don't see it on webpages. The only place where the problem arises is with closing </td> tag.

If you have some table template that looks like this:
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
. . .

the whitespace is already there! So the only thing you can do is to remove it manually. Or create a new template:
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>

If you look at the code generated by any good WYSIWYG editor you'll see that </td> never comes separately on next line.

By the way, spaces between </td> and </tr> doesn not cause any problems.

good luck
 
To lesina:
>>Most of the times, when you have a more_then_one_line table, the image can be expanded(and so, the width or height is not what you defined) to fill the row (tr)or the td (just to be in line with the other rows).

This is not correct. Image size do not &quot;expand&quot;, it always the same as defined. But the table cell with image can expand. Feel the difference? It often comes if table cell dimentions are not specified, and extra whitespaces (the subject of this thread) exists.

The sulition is simple: add [tt]<td width=&quot;&quot;>[/tt] to table cells (no need to define [tt]height[/tt], because an image will do it itself) and remove whitespaces before [tt]</td>[/tt].
That's all!
 
Hi starway,

in theory that should be right, but let me tell you that image can be minimized or expanded, it has happened to me lots of times. It's not a metter of spaces...when the cell is defined to be smaller then the image, the size you're using on the <img src> doesn't work in fact because table measures have more priority then img measures.
In real world, if the table is not totally specified (with widths and heights), you can have image shorting happening.
 

...when the cell is defined to be smaller then the image ...
c'mon, is there any logical reason to do this?!?
 
I seem to remember reading some time back that Netscrap likes the <td> and </td> to be on one line. I could be wrong, maybe a different tag, but I'm pretty sure that was it. It's definitely legal HTML to NOT be on the same line, but that sort of thing never stopped NS before. Like instead of making your <hr/> tag you do it like this: <hr />. For some reason the lack of space breaks NS (maybe <br /> tag, I always add the space by habit and I forget the details).

Does this sound familiar to anyone or am I a moron?
 
Hey guys,

Just for the record starway, I ONLY use Notepad
since there are NO good wysiwyg editors.

And yes Yegolev, you are a moron ;-) No just kidding,
but what does <br /> and <hr /> do? I take that you mean
</hr> and </br> (although you do NOT need to close a <br>) BobbaFet

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
The reason that you seem to be able to get away with using <td> tags on different lines sometimes is that it just doesn't make a significant different when the content of the cell is text. BUT, the HTML standard says that, except within special tags like <pre>, all consecutive whitespace (spaces, tabs and returns) are compressed to a SINGLE SPACE, which shows up around the edge of a graphic that you expect to fill a table cell completely. There's nothing wrong or buggy with this behaviour, it works exactly like it's supposed to. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top