473,756 Members | 4,046 Online
Bytes | Software Development & Data Engineering Community
+ 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 1922
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 <inputelement s 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 <inputelement s 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 <inputelement s 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.comwro te:
>
>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 <inputelement s 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 <inputelement s 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
10568
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 type="text/javascript"> <!]> </script> <script type="text/javascript"
0
3115
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, which needs a Quicktime plugin, and one Java applet. He's also kindly supplied me with sample HTML code for each. The code looks like this (simplified):
1
3185
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" width="320" height="312" ShowControls="1" ShowStatusBar="1" invokeURLs="0" autostart="1" enableErrorDialogs="0" ></EMBED> but I need video area bg color to be white, it defaults to black and I
2
2047
by: chaitatp | last post by:
Hi guys, I have posted a similar question before but this post has some different. The similar link is: http://groups-beta.google.com/group/comp.lang.javascript/browse_thread/thread/a4e7317eee02579f/13714e97d19ff2a7#13714e97d19ff2a7 When I put <embed> in an <iframe> using javascript, I can't see the embedded object in Firefox. But if I put other tags say, <b>hello</b> or <img src="..."/>, it works well. I am wondering if it is...
2
3097
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 a second aspx page to generate the svg for the embed. svgchart.Controls.Clear(); string strSRC = "./DesktopModules/Enterprise/BusinessRuleSVG.aspx";
2
3288
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' pluginspage='http://microsoft.com/windows/mediaplayer/en/download/' id='mediaPlayer' name='mediaPlayer' displaysize='4' autosize='-1'
2
3628
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" height="500"></embed> When the mouse passes over the navigation bar, the drop downs are hidden behind the PDF page.
3
3380
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, &gt ,&ltCompany&gt to display '<', '>' and '<Company>' respectively. But is there any freeware code available which could implement the above functionality without having to use &gt,&lt and such stuff???
1
1995
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. I even tried this with a flash swf file and that never worked either. Still get validation errors and IE7 refuses to run it...any ideas on how to fix this?
0
9431
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10014
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9844
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9819
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9689
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7226
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5119
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5289
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2647
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.