Topic: p-tag in a p-tag (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=30513" title="Pages that link to Topic: p-tag in a p-tag (Page 1 of 1)" rel="nofollow" >Topic: p-tag in a p-tag <span class="small">(Page 1 of 1)</span>\

 
GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 08-31-2008 19:14

hi just a quick question: is it allowed (w3c-valid) to have a p-tag inside a p-tag?

if not? is there an alternative?
i am using a wysiwyg-editor to generate text for a webpage and this contains p-tags.

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 08-31-2008 19:44

Nested P elements are schabernack.

It's just unpossible per the HTML4 specification of the P element. The ending tag of P is optionnal in HTML, plus Ps can not contain any other block level element ( including P of course ).


Of course it is possible to do schabernack programmatically, but I fail to get the semantic of nested P elements. Plus the user agent will/should close the parent P the second you append a P in it. Therefore a page containing nested P elements should validate, and its DOM tree will feature sibling P elements.


HTH,



(Edited by poi on 08-31-2008 20:02)

DL-44
Lunatic (VI) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 08-31-2008 19:56
quote:

GRUMBLE said:

if not? is there an alternative?



An alternative to what, exactly?
What are you trying to accomplish that has you wanting to nest paragraphs in the first place?

As to the semantics, as poi alluded to, there is just no such thing as a paragraph within a paragraph; a paragraph is a purely singular object. It would make no sense...

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 08-31-2008 21:16

Holy smoke!

I just tweet'ed with a friend from work and he pointed to me that it IS possible to nest P elements in an evil evil way :

code:
<p>This is the first paragraph 
	<object>
		<p>This is the second paragraph 
			<object>
				<p>This is the third paragraph</p>
			</object>
		</p>
	</object>
</p>

This of course is pure valid HTML. It makes no sense whatsoever to have a P in a P but it is sorta kinda technically possible. If an OBJECT is inside a P, or any element only accepting inline children, the text fallback should be a SPAN or simply a text node.

Want more weird a** behavior from HTML4.01 ? No problem. OBJECTs are allowed in the HEAD tag. Which mean that you can load something with various fallbacks, including "regular" markup, inside the HEAD.

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 08-31-2008 21:23

thanks for the answers, guys!

the problem is, that i have a website, where content is edited using a wysiwyg-editor (tinymce) which produces lots of p-tags.

and i need to format all that content in a paragraph. i guess i will do span or div.

thanks!

Nathraiben
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2008

posted posted 09-01-2008 05:56

DIV isn't allowed, either (since it's block level), so best use SPAN.

(And no way to deactivate tinymce? Normally there should be an option to use a text-only editor instead - though in this case sticking with the P and SPAN probably is the best way to do it, anyway.)

(Edited by Nathraiben on 09-01-2008 05:57)

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 09-01-2008 13:59

<div><p>foo</p><p>bar</p></div> OTOH is perfectly ok in all regards.

reisio
Paranoid (IV) Inmate

From: Florida
Insane since: Mar 2005

posted posted 09-01-2008 23:32

http://www.cs.tut.fi/~jkorpela/html/strict.html



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu