5 replies [Last post]
ed209
Offline
Regular
UK, Midlands
Last seen: 13 years 3 weeks ago
UK, Midlands
Joined: 2004-06-01
Posts: 28
Points: 0

Hi,

I have used the following xhtml 1 transitional on a web - here's the problem snippet :

<span class="aStyle">
   <p>My Text In Here</p>
</span>

then my linked stylesheet has this

.aStyle p{
 
    css properties in here

}

the idea is that the above style only affects the <p> part of the <span> it's in.

When I try and validate it at http://validator.w3.org/ I get these errors for all the <p> tags:


Line 31, column 29: document type does not allow element "p" here; missing one of "object", "applet", "map", "iframe", "button", "ins", "del" start-tag

<span class="standardtext"><p>A tax exempt savings plan specially designed for y

Which leads me to believe that you can't have a <p> inside a <span>?

thepineapplehead
thepineapplehead's picture
Offline
Guru
Last seen: 1 week 2 days ago
Joined: 2004-06-30
Posts: 9668
Points: 801

&lt;p&gt; inside a &lt;span&gt; - doesn't validate

You shouldn't need to - spans are normally used for styling text inside a div. If you need to, use something like the bold or italic tag instead of p.

Verschwindende wrote:
  • CSS doesn't make pies

ed209
Offline
Regular
UK, Midlands
Last seen: 13 years 3 weeks ago
UK, Midlands
Joined: 2004-06-01
Posts: 28
Points: 0

&lt;p&gt; inside a &lt;span&gt; - doesn't validate

does that mean you can only have <p> <span> and not <span><p>?

Wouldn't <span><i> make it all italic though?

thanks for your reply,ed.

co2
co2's picture
Offline
Leader
UK
Last seen: 11 years 40 weeks ago
UK
Joined: 2003-09-17
Posts: 721
Points: 0

&lt;p&gt; inside a &lt;span&gt; - doesn't validate

A span element is what is known as an inline HTML element. A paragraph is a block element. W3C standards dictate that inline elements such as a span cannot contain a block level element such as a paragraph (or div etc.)

So, yes, you can use <p><span>... but not <span><p>.

Smile

The next sentence is true. The previous sentence is false. Discuss...

ed209
Offline
Regular
UK, Midlands
Last seen: 13 years 3 weeks ago
UK, Midlands
Joined: 2004-06-01
Posts: 28
Points: 0

&lt;p&gt; inside a &lt;span&gt; - doesn't validate

thanks Laughing out loud

thepineapplehead
thepineapplehead's picture
Offline
Guru
Last seen: 1 week 2 days ago
Joined: 2004-06-30
Posts: 9668
Points: 801

&lt;p&gt; inside a &lt;span&gt; - doesn't validate

Alternatively you could just create a seperate class for the p, example myclass, then call it like so:

<p class="myclass" >
stuff
</p >

Should be easier.

Verschwindende wrote:
  • CSS doesn't make pies