Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Headless style blocks - an observation

Status
Not open for further replies.

BabyJeffy

Programmer
Sep 10, 2003
4,189
GB
I was modifying some code at work the other day and had to do a double-take. The page rendered fine (IE, FF, NS, Opera - all on Windows) which was obviously a good thing... but when I was viewing the source I found multiple <style> blocks... but not a single one was in the <head> section of the page.

Let me mention again that the page was rendering fine in those 4 browsers.

I have always stood by the statement that all <style> blocks should live in the <head> section (and by association I assumed that they wouldn't work if placed anywhere else. This may very well be the case when you validate against a specific doctype... but "out of the box" it appears to work.

I am not advocating this kind of behaviour - please don't think this for a moment. I was just a bit shocked and wanted to share the discovery with you. Maybe someone else has already discussed this... I haven't seen it mentioned here before.

<insert obligatory link to the w3c site here/>

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Like any other invalid code, you can't assume anything. Browsers are written to be tolerant of validation errors, attempting to render what they think the author intended (much the annoyance of fanatical standardistas). I'm not surprised that browsers handle <style> elements in the <body>, but I'd also not be surprised if they handled them slightly differently.

That's the real reason to stick to standards and validate your site - not that browsers won't render invalid code, but that they'll handle it differently depending on their guesses as to what you really meant.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
You may not know this either, but you can also use <script> blocks in the body of a document.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
According to the specs, . . .

. . . <script> blocks are valid in the body of a document.
. . . <style> is not valid in the body of a document.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top