Forum Moderators: open

Message Too Old, No Replies

Lists between <p></p>

not W3 compliant?

         

Lupi

11:40 pm on Mar 11, 2005 (gmt 0)

10+ Year Member



Hi,

please have a look at the following code and explain me why it is not W3 HTML Transitional 4.01 compliant!


<p><ol id="css">
<li>text</li>
<li>text</li>
<li>text</li>
<li>text</li>
<li>text</li>
</ol></p>

DOC TYPE is HTML Transitional 4.01 (loose), everything except for that piece of code validates. The HTML Validator marks </p>, saying it would be an end tag for an element that is not open.

What's wrong?

Lupi

tedster

12:21 am on Mar 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A list is its own kind of element - it's not part of a paragraph.

When a list is openend (with dl, ol, ul and so on) then that open element will close any previous paragraph that is still open. Because a </p> is optional and could have omitted, the parser will just assume a </p> before the <ol> and that makes the </p> after the </ol> "extra".

So you don't need the <p> in this case.

SuzyUK

12:43 am on Mar 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>>What's wrong?

Technically the <p> is a block level element, as it creates an element which displays as a block, but that particular block element can can only contain *inline* elements [w3.org].

<!ELEMENT P - O (%inline;)* -- paragraph -->
<!ATTLIST P
%attrs; -- %coreattrs, %i18n, %events --
>

My Red but means = The <p> can *only* contain inline elements

A list ~ OL, UL, DL ~ is (in my books anyway) a block level element ~ but it is technically defined as a list element which may not be helpful in in it's own right, but the children (descendants) of these list elements <li> [w3.org] and <dd> [w3.org] are defined as flow [w3.org] elements which means they can contain either block [w3.org] or inline [w3.org] elements ..

phew.. that means that the <p> cannot (validly) contain a list because if any particular <li> or <dd> were to contain a block level element as it's "validly allowed to" the <p> validation rule is broken, which is what is happening..

Suzy

tedster

1:05 am on Mar 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Which brings up a question I wonder about. It's not uncommon for me to use CSS to change the <img> tag from inline to block. Does this mean I'm not technically correct by putting such a changed <img> element within a <p>?

Neither the CSS validator nor the HTML validator will see an error, but in the combination between the two, might I cause some browser, some day, to have a problem?