Forum Moderators: open

Message Too Old, No Replies

TABLE inside P not valid?

         

mehh

5:39 pm on Nov 3, 2007 (gmt 0)

10+ Year Member



When validating one of my clients sites I was shocked to find tables put inside P tags. quck sample code to show you what I meen:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Paragraphs And Tables </title>
</head>
<body>
<p>
<table>
<tr><th>&nbsp;</th><th>Row Number</th></tr>
<tr><td>1st row</td><td>1</td></tr>
<tr><td>2nd row</td><td>2</td></tr>
</table>
</p>
</body>
</html>

This is easly solved by putting OBJECT tags round the table, but why is it nessesary in the first place?

encyclo

6:06 pm on Nov 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A paragraph cannot contain any other block-level elements - and as the closing
</p>
is optional (in HTML parsing mode), the paragraph is closed by any following block.

Using an

object
to enclose a
table
is inappropriate (a
table
does not fit the definition of an object in this instance). A
table
is a block-level element on its own, it does not need any container.

ronin

9:06 pm on Nov 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This code was written by someone who learned to code in 1996 and hasn't kept abreast of developments.

What they meant was:

<table style="margin:1.2em 0;">
...
</table>

That's why they wrote:

<p>
<table>
...
</table>
</p>

mehh

8:07 pm on Nov 5, 2007 (gmt 0)

10+ Year Member



A paragraph cannot contain any other block-level elements - and as the closing </p> is optional (in HTML parsing mode), the paragraph is closed by any following block.

Using an object to enclose a table is inappropriate (a table does not fit the definition of an object in this instance). A table is a block-level element on its own, it does not need any container.


This is XHTML 1.0 strict so the closing </p> is nessesary, and I had to use the OBJECT tag to get it to validate. If you copy the above code into the W3 validator you get:
Validation Output: 1 Error
Line 8, Column 6:
document type does not allow element "table" here; missing one of "object", "ins", "del", "map", "button" start-tag.

@Ronin
I put the table inside the P tag because of semantic reasons not for the layout. The pages layout is actualy tableless and I am only using the table to show information.

encyclo

8:29 pm on Nov 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Whether for XHTML or HTML, you cannot place any other block element within a paragraph.

The error message is misleading - the problem will be higher-up in the code, with an unclosed or badly-nested element occuring before the table. A

table
element should never be enclosed within an
object
.

mehh

4:04 pm on Nov 6, 2007 (gmt 0)

10+ Year Member



fixed it. thanks for you help. Sorry I didn't understand your earlier message encyclo, I was tired when I read it.