views:

495

answers:

3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
</head>
<body>

<table width="100%" cellspacing="0" cellpadding="0">
    <tr>
     <td align="right" colspan="5">
      <span class="validationInline">*</span> 
      <span class="hint">Required fields</span>
     </td>
    </tr>
    <tr>
     <td colspan="5" background="http://media.monster.com.hk/bgr_8.gif"&gt;
      <img src="/static/cleardot.gif" height="1" width="1" />
     </td>
    </tr>
</table>

</body>
</html>

Can check it out here: http://maishudi.com/tt2.html

I've known it's caused by DOCTYPE ,because deleting that part will make it normal:

http://maishudi.com/tt.html

So what's wrong?How can I make it work with the DOCTYPE ?

A: 

background isn't a standard attribute for TD elements is the reason. Instead use:

style="background: url(/path/to/image.png);"

As for your 1 pixel image, I assume this is simply to make the table cell appear? If so, that's not the advised way of doing it. You can either do:

table { empty-cells: show; }

in CSS although I don't think IE6 supports that. The more standards compliant way is to use a non breaking space:

<td>&nbsp;</td>
cletus
not working,you can check it out http://maishudi.com/tt3.html
Shore
+1  A: 

Note: this probably depends on the browser.
The size of block-level element (td, div, etc) if not specified will only be as big as needed, according to the space taken by its content. If specified, it will try to expand accordingly, except if the content is bigger, in which case it will expand as necessary.

In your example, the cell contains a single character (the non-breaking space), which take the size of single line. Hence, the block element must be at least 1 line-height high; it can't assume any smaller size. This is why your height declaration was ignored.

You may want to use this style:

line-height: 1px;

This sets the line-height to 1px. Line-height is not an element, so the above rule doesn't apply.

RichN
Works like charm! But can you explain why height has no effect on td?
Shore
It's based on browsers also. Some browsers expect text content within elements. This can also happen with divs.
Ólafur Waage
Edited my answer.
RichN
+1  A: 

Add a style block with this rule

td img {display: block;}

and see https://developer.mozilla.org/en/Images,_Tables,_and_Mysterious%5FGaps for a full explanation.

Alohci