Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Weird validation result
August 24, 2007, 2:55 pm
rate this thread
I've tried validate something like (declaration excluded) :
It doesn't validate, as <h1>'s DTD is : <!ELEMENT (%heading;) - -
(%inline;)* -- heading -->
meaning that h1 can only contains inline element.
That's strange as DIV DTD is : <!ELEMENT DIV - - (%flow;)*
-- generic language/style container -->
with flow being "block or inline"
That's also strange as the same code with p in-place of h1 validate:
and P DTD ( <!ELEMENT P - O (%inline;)* -- paragraph --> )
is declared like H1
Also, both P and H1 are declared in block level elements.
What is the reason behind this ?
Does DIV transmutate to inline only in P or is there a rule for this ?
Re: Weird validation result
Right, but that's irrelevant to what's happening with your code.
The difference is that H1 has "- -" and P has "- O". The end tag is
optional for P, which means that the user agent closes the P element
automatically as soon as it encounters the beginning of another element
that can't be nested inside or the end of an element within which the P
element is nested. In your example, the validator deems the P to be
closed as soon as it encounters the start tag for the DIV, and it
interprets the two elements as a P element *followed by* a DIV element,
not as a P element *containing* a DIV element. However, the validator
will also flag the closing </p> as an error because no P element is open
at that point. Did you notice that?
The H1 end tag isn't optional, and since you haven't explicitly closed
the H1 element at the point where the DIV begins, the validator treats
your code is nesting a DIV inside the H1, which isn't allowed.
This has no bearing on what they can or can't contain.
Re: Weird validation result
Don't you think that's important?
Right; what's *inside* a <h1> must be inline.
Not strange; this means that what's *inside* a <div> is block or inline.
But the element itself is block-level. Therefore no good inside a <h1>.
Because the closing tag for <p> is optional, a browser can (and I
believe most do, but I've forgotten the exception(s)) terminate the p
element when it hits the <div>. When it gets to the coded </p> tag, it
then has to decide what to do about it. I believe most (all?) browsers
ignore it silently as a harmless coding error.
We just had a discussion about this here (or hereabouts) roughly 3 to 5
See also http://www.w3.org/TR/html401/struct/global.html#h-7.5.4 if you
Not exactly. H1 is declared as
<!ELEMENT (%heading;) - - (%inline;)* -- heading -->
so the closing tag </h1> is required.
I'm not sure what you mean by this sentence.
No, yes, see above.
Pondering the value of the UIP: http://blinkynet.net/comp/uip5.html
- » Learning HTML: building a Web Site: What do you think of this www?
- — Next thread in » HTML Markup Language