Forum Moderators: open
<p class="articleblock">
Headline
<p class="articlecontent">some content</p>
</p>
This is generated by my content management system, so I'll have to dig around the PHP to address this, but I thought it was OK to nest one block level element within another?
The W3 XHTML validator is dinging me for the following code
...rightfully so.
Think about it for a brief moment: "a paragraph within a paragraph."
Now do you see why ya got 'dinged?'
In the proposed next release of XHTML, v. 2.0, paragraphs will be allowed to contain true block elements. But even here [w3.org] nesting paragraphs within paragraphs will not be allowed.
- papabaer
OK to nest one block level element within another
More exactly, only a block level element can contain other block level elements. But this does not mean any block level element can be nested within any other block level element. Many of these combinations we wouldn't usually think of trying - such as nesting a div within an H1 tag.
There are specific elements that cannot be nested, but that people often try to nest anyway - blockquote cannot be nested within a paragraph tag, for instance. Nor can a list element be nested within a <p>. Even in HTML 4, browsers will interperet the appearance of a blockquote as implying a </p> if one does not exist ion the code.
This can have implications in your CSS -- any class applied to a <p> stops taking effect as soon as a blockquote appears in the HTML.