473,486 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Why can't I embed divs in a <p>?

Sorry if this is a dumb question, but with the following code:

<p>
<div>Block1</div>
<div>Block2</div>
</p>

For xhtml1-strict.dtd, the W3C validator gives:
document type does not allow element "div" here; missing one of
"object", "ins", "del", "map", "button" start-tag.

Whereas with:
<div>
<div>Block1</div>
<div>Block2</div>
</div>

Is it quite happy :-/

I thought both <divand <pwere block elements, but I'm obviously
missing some fundamental difference :-/

Nov 10 '06 #1
7 1911
Hello,

li************@hotmail.com wrote:
Sorry if this is a dumb question, but with the following code:

<p>
<div>Block1</div>
<div>Block2</div>
</p>

For xhtml1-strict.dtd, the W3C validator gives:
document type does not allow element "div" here; missing one of
"object", "ins", "del", "map", "button" start-tag.

Whereas with:
<div>
<div>Block1</div>
<div>Block2</div>
</div>

Is it quite happy :-/

I thought both <divand <pwere block elements, but I'm obviously
missing some fundamental difference :-/
Being a 'block' element (vs. 'inline') only tells *where* the element can be
used, not which elements it can contain.
The content model for P only allows inline elements, whereas DIV can contain
both block and inline elements.
HTH

--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/
Nov 10 '06 #2
li************@hotmail.com wrote:
Sorry if this is a dumb question, but with the following code:

<p>
<div>Block1</div>
<div>Block2</div>
</p>

For xhtml1-strict.dtd, the W3C validator gives:
document type does not allow element "div" here; missing one of
"object", "ins", "del", "map", "button" start-tag.

Whereas with:
<div>
<div>Block1</div>
<div>Block2</div>
</div>

Is it quite happy :-/

I thought both <divand <pwere block elements, but I'm obviously
missing some fundamental difference :-/
They are both block elements, but all block elements aren't the same in
all ways.

In what way is your chunk of content that includes two block elements
logically a single paragraph? When you read a paragraph in a book or a
report, it's all one block, right?
Nov 10 '06 #3
On 10 Nov 2006 06:40:32 -0800, li************@hotmail.com wrote:
>Sorry if this is a dumb question, but with the following code:

<p>
<div>Block1</div>
<div>Block2</div>
</p>

For xhtml1-strict.dtd, the W3C validator gives:
document type does not allow element "div" here; missing one of
"object", "ins", "del", "map", "button" start-tag.
Only inline elements are allowed inside a <pelement.
>Whereas with:
<div>
<div>Block1</div>
<div>Block2</div>
</div>

Is it quite happy :-/
Yes, because <divis designed for grouping block elements.
>I thought both <divand <pwere block elements, but I'm obviously
missing some fundamental difference :-/
They are both block elements. That doesn't mean they are equivalent
elements. <oland <ulare block elements too, but they can only
contain <lielements.

Semantically the <pis meant to contain a paragraph, a single thought
in text (more or less). <divhas little semantic meaning except to
group other block elements for purposes such as providing a hook for CSS
or javascript.

Nov 10 '06 #4
Semantically the <pis meant to contain a paragraph, a single thought
in text (more or less). <divhas little semantic meaning except to
group other block elements for purposes such as providing a hook for CSS
or javascript.
OK, so why is it necessary to contain <inputelements within a
paragraph?

This is what caused my problems in the first place. I had aligned
various controls in my form by encasing them in <div>s and floating
etc.

The W3C validator complained that all my <inputelements shouldn't be
there because they weren't contained by a <p>

Wrapping the lot with a <pcaused the error that started this thread.

I could replace all the <div>s with <p>s, but then all the margins will
be messed up (I don't WANT them in paragraphs!)

Thanks for your help

Nov 10 '06 #5

li************@hotmail.com wrote:
I thought both <divand <pwere block elements,
There's no such thing as a simple "block element". There are elements
that are themselves treated as block (or not), and elements that can
contain block elements (or not). Usually these are the same for each
element, but if you read the DTD for <pthen you'll see that <pis
one, but can only contain inlines.

This is all fixed and unchangeable. However there's also <span>
(happily sits inside a <p>) and you _can_ change the CSS behaviour of
this with display:block; so that it looks like a <div>.

It's also somewhat curious as to what placing a block element inside a
paragraph means anyway. It might even be better to use <divfor the
outer container, rather than to stretch <ponto something that's not
really a paragraph.

Nov 10 '06 #6
li************@hotmail.com wrote:
>
The W3C validator complained that all my <inputelements shouldn't be
there because they weren't contained by a <p>
Are you sure it said they *had* to be contained by <p>, or was that only
a suggestion? Form elements do need to be contained by a block element,
but it doesn't have to be <p>. Try fieldset, div or table.

--
Berg
Nov 10 '06 #7
On 2006-11-10, li************@hotmail.com <li************@hotmail.comwrote:
>
>Semantically the <pis meant to contain a paragraph, a single thought
in text (more or less). <divhas little semantic meaning except to
group other block elements for purposes such as providing a hook for CSS
or javascript.

OK, so why is it necessary to contain <inputelements within a
paragraph?

This is what caused my problems in the first place. I had aligned
various controls in my form by encasing them in <div>s and floating
etc.

The W3C validator complained that all my <inputelements shouldn't be
there because they weren't contained by a <p>

Wrapping the lot with a <pcaused the error that started this thread.

I could replace all the <div>s with <p>s, but then all the margins will
be messed up (I don't WANT them in paragraphs!)
Do you mean replace the <p>s with <div>s?

You can always set <divto have the same margins as <phas by default.

e.g.

div.p
{
margin: 1.12em 0;
}

<div class="p">
</div>

for example, although "p" may not be the best name to use.

If you're not using <pto mark a "thought", or something resembling a
"paragraph" in an abstract sense, just use <divinstead.

The fact that the HTML DTD doesn't allow, for example, "block" elements
inside "inline" elements seems to me a bit of an anachronism. In today's
world, HTML isn't supposed to be describing blocks and lines, but
abstract things like "lists" and "tabular data". It's CSS's problem if
it doesn't like a display: block element inside a display: inline
element (although actually it is required to tolerate just about
anything).

HTML has all kinds of requirements about what you can and can't nest
inside what. CSS on the other hand only cares what styles apply, and as
far as it's concerned, tags are nothing more than indices into the bag
of selectors it picks up from the stylesheets and style elements. It
allows any structure you like (although certain things are a bad idea,
like absolutely positioned table cells).

So if you're getting validation errors that are meaningless to you, just
start watering things down into a div soup.

In fact the validation errors probably don't matter a lot in practice
since modern browsers will allow invalid structure anyway and render
according to the styles. But you should probably forget I said that.
Nov 10 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
10531
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script...
0
3097
by: Wolfgang Schwanke | last post by:
Dear usenet, I'm having the following small problem. I've been ask to add some Quicktime panoramas to a website. The author of the panoramas has made two versions of each: One in MOV format,...
1
3171
by: Frances Del Rio | last post by:
I have this tag to embed a video: <EMBED type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/" SRC="video.wmv" name="Video"...
2
2032
by: chaitatp | last post by:
Hi guys, I have posted a similar question before but this post has some different. The similar link is: ...
2
3079
by: Cris Curtis | last post by:
When I use an embed tag that uses a dynamic aspx page, the dynamic aspx page appears to get called 2 times instead. Below is code that adds an embed tag to a placeholder control that will use...
2
3269
by: Annu | last post by:
Hi I need help on <enbed> tag. Following code(No 1) is working properly on windows but on linux code no.2 is not working Code No 1: <EMBED type='application/x-mplayer2' ...
2
3615
by: John | last post by:
I have CSS drop down navigatoon bar and it works fine. However, when I have page where I have an <embed - needed to show a PDF file, such as: <embed src="Security.pdf" width="900"...
3
3342
by: ajay2552 | last post by:
Hi, I have a query. All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it? One method is to use &lt,...
1
1980
by: Andy B | last post by:
I am trying to embed mp3 files in a web page by using the <embedtag. Every time I save the page I get xhtml validation(): embed tag no longer supported. When I run the page... I get nothing at all....
0
7094
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6839
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5427
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3066
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.