469,365 Members | 1,889 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,365 developers. It's quick & easy.

<style> tag inside HTML body - valid?

Hi,

I'm programming some PHP discussion board that is supposed to appear
inside
the content area of a proprietary CMS. As I need some more styles than the
standard stylesheet provides, I just added a <style> tag inside my HTML
code. It works fine in all the browsers I tested, but it seems to be more
of
a hack than a valid solution.

Of course I did some research, but without success. So here is my question
to you:

Do the HTML+CSS standards allow <style> tags inside the <body>?

Regards,
Matthias

Aug 1 '05 #1
15 32288
On Mon, 1 Aug 2005 20:28:38 +0200, Matthias Hullin
<ne*******@matthiasREMOVETHIS.hullin.net> wrote:
Of course I did some research, but without success. So here is my question
to you:

I wounder where you did your research
Do the HTML+CSS standards allow <style> tags inside the <body>?


<http://www.w3.org/TR/html401/present/styles.html#edef-STYLE>
--
,-- --<--@ -- PretLetters: 'woest wyf', met vele interesses: ----------.
| weblog | http://home.wanadoo.nl/b.de.zoete/_private/weblog.html |
| webontwerp | http://home.wanadoo.nl/b.de.zoete/html/webontwerp.html |
|zweefvliegen | http://home.wanadoo.nl/b.de.zoete/html/vliegen.html |
`-------------------------------------------------- --<--@ ------------'

Aug 1 '05 #2
Hi Barbara,

thank you for your reply. This page I already knew, of course:
The STYLE element allows authors to put style sheet rules in the head of
the document. HTML permits any number of STYLE elements in the HEAD
section of a document.


Still I found no information whether it is forbidden to use style elements
elsewhere.

Regards,
Matthias

Aug 1 '05 #3
[Quote fixed --> Please include the part you quote
and attribute it too. Reply underneath the quote.]

On Mon, 1 Aug 2005 20:50:46 +0200, Matthias Hullin
<ne*******@matthiasREMOVETHIS.hullin.net> wrote:
Barbara de Zoete:
On Mon, 1 Aug 2005 20:28:38 +0200, Matthias Hullin
<ne*******@matthiasREMOVETHIS.hullin.net> wrote:
Do the HTML+CSS standards allow <style> tags inside the <body>?
<http://www.w3.org/TR/html401/present/styles.html#edef-STYLE>

thank you for your reply. This page I already knew, of course:


<from it:>
The STYLE element allows authors to put style sheet rules in the head of
the document. HTML permits any number of STYLE elements in the HEAD
section of a document.

Still I found no information whether it is forbidden to use style elements
elsewhere.


Do you think one can even begin to list the things that you are _not_ supposed
to do?
Secondly: why haven't you just tried it? Create a mockup page with appropriate
doctype and get it validated. See what happens.

--
,-- --<--@ -- PretLetters: 'woest wyf', met vele interesses: ----------.
| weblog | http://home.wanadoo.nl/b.de.zoete/_private/weblog.html |
| webontwerp | http://home.wanadoo.nl/b.de.zoete/html/webontwerp.html |
|zweefvliegen | http://home.wanadoo.nl/b.de.zoete/html/vliegen.html |
`-------------------------------------------------- --<--@ ------------'

Aug 1 '05 #4
max
[snip]
Do you think one can even begin to list the things that you are _not_ supposed
to do? I don't expect he does - which might be why he turned to the newsgroup for
some time-saving assistance. It's a shame he got yelled at.Secondly: why haven't you just tried it? Create a mockup page with appropriate
doctype and get it validated. See what happens.

Re-read his original post; he says he *has* tried it.
I get the impression he is wondering if his result is down to a fortuitous
combination of circumstances and that he is asking if the ever-helpful
people here can guide him to the definitive Rule.
Aug 1 '05 #5
Els
max wrote:
[snip]
>Do you think one can even begin to list the things that you are _not_ supposed
>to do? I don't expect he does - which might be why he turned to the newsgroup for
some time-saving assistance. It's a shame he got yelled at.
>Secondly: why haven't you just tried it? Create a mockup page with appropriate
>doctype and get it validated. See what happens.


Re-read his original post; he says he *has* tried it.


Re-read Barbara's last two sentences: ".. and get it validated. See
what happens."
I get the impression he is wondering if his result is down to a fortuitous
combination of circumstances and that he is asking if the ever-helpful
people here can guide him to the definitive Rule.


That definitive rule is the answer of the validator.

--
Els http://locusmeus.com/
Sonhos vem. Sonhos vo. O resto imperfeito.
- Renato Russo -
Now playing: David Bowie - Wild Is the Wind
Aug 1 '05 #6
[ You too should attribute the quotes ]

On Mon, 01 Aug 2005 19:27:27 GMT, max <ma****@hotmail.com> wrote:
Barbara de Zoete:
> [ and set your newsclient to _not_ add those additional
spaces before the >> It breaks the mechanism for others
to cleanly and recognisably quote ]
Do you think one can even begin to list the things that you are _not_
supposed to do?
I don't expect he does - which might be why he turned to the newsgroup for
some time-saving assistance.


Well, knowing one cannot list what one is not supposed to do, one should realise
that what is listed is all there is. So, if it sais <q>The STYLE element allows
authors to put style sheet rules in the head of the document.</q> it implicitely
states the style element is not supposed to go anywhere else.
It's a shame he got yelled at.

I don't see any yelling? Where is it.
Secondly: why haven't you just tried it? Create a mockup page with
appropriate doctype and get it validated. See what happens.

Re-read his original post;


So I did.
he says he *has* tried it.

I don't actually see him sayin that anywhere. It could be implied by his <q>but
it seems to be more of a hack than a valid solution</q>
I get the impression he is wondering if his result is down to a fortuitous
combination of circumstances

If that is what he is woundering about, he should have provided an URL.
and that he is asking if the ever-helpful
people here can guide him to the definitive Rule.


What makes you think he _would_ trust and believe any of the 'ever-helpful
people here' in favour of the validators of w3.org or htmlhelp.com of which he
appearently doubts the outcome?

--
,-- --<--@ -- PretLetters: 'woest wyf', met vele interesses: ----------.
| weblog | http://home.wanadoo.nl/b.de.zoete/_private/weblog.html |
| webontwerp | http://home.wanadoo.nl/b.de.zoete/html/webontwerp.html |
|zweefvliegen | http://home.wanadoo.nl/b.de.zoete/html/vliegen.html |
`-------------------------------------------------- --<--@ ------------'

Aug 1 '05 #7
Els wrote:
max wrote:
I get the impression he is wondering if his result is down to a
fortuitous combination of circumstances and that he is asking if the
ever-helpful people here can guide him to the definitive Rule.


That definitive rule is the answer of the validator.


Not really. The W3C Validator is just a piece of software that can be buggy
like any other (non-trivial) piece of software. The only definitive answer
can be found in the HTML specification as published by the W3C.
And the Validator (even if correctly implemented) only verifies a limited
part of this specification, so it can only testify that a document violates
a rule of the spec and not, if it conforms to the spec (saying that a
document is 'valid' is a technical term that means less than 'conforms to
the spec').

--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
Aug 1 '05 #8
> Els wrote:
That definitive rule is the answer of the validator.

Benjamin Niemann wrote: Not really. The W3C Validator is just a piece of software that can be buggy
like any other (non-trivial) piece of software. The only definitive answer
can be found in the HTML specification as published by the W3C.
And the Validator (even if correctly implemented) only verifies a limited
part of this specification, so it can only testify that a document violates
a rule of the spec and not, if it conforms to the spec (saying that a
document is 'valid' is a technical term that means less than 'conforms to
the spec').


Basically ACK. But checking the content model of an element is a thing
that a validator can do, because it (content model) can be described
with DTD syntax. So a validator will bark on an HTML style element
within an HTML body element.
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
Aug 1 '05 #9
Johannes Koch wrote:
Els wrote:
That definitive rule is the answer of the validator.


Benjamin Niemann wrote:
Not really. The W3C Validator is just a piece of software that can be
buggy like any other (non-trivial) piece of software. The only definitive
answer can be found in the HTML specification as published by the W3C.
And the Validator (even if correctly implemented) only verifies a limited
part of this specification, so it can only testify that a document
violates a rule of the spec and not, if it conforms to the spec (saying
that a document is 'valid' is a technical term that means less than
'conforms to the spec').


Basically ACK. But checking the content model of an element is a thing
that a validator can do, because it (content model) can be described
with DTD syntax. So a validator will bark on an HTML style element
within an HTML body element.


That's what I meant by saying "it can only testify that a document
violates a rule of the spec"

--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
Aug 1 '05 #10
On Mon, 1 Aug 2005, Benjamin Niemann wrote:
That's what I meant by saying "it can only testify that a document
violates a rule of the spec"


This is off-topic for the present group, but the validator does what
validators do. You seem eager to confuse that with something else.

Aug 1 '05 #11
Alan J. Flavell wrote:
On Mon, 1 Aug 2005, Benjamin Niemann wrote:
That's what I meant by saying "it can only testify that a document
violates a rule of the spec"
This is off-topic for the present group,


Agreed, and the issue is not of importance for the OP's question.
but the validator does what
validators do. You seem eager to confuse that with something else.


I was referring to "That definitive rule is the answer of the validator."
which is true enough for most practical cases, but not true enough to use
the attribute 'definitive'...

--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
Aug 2 '05 #12
"Matthias Hullin" <ne*******@matthiasREMOVETHIS.hullin.net> wrote in message
news:dc**********@news.uni-kl.de...
Hi,

I'm programming some PHP discussion board that is supposed to appear
inside
the content area of a proprietary CMS. As I need some more styles than the
standard stylesheet provides, I just added a <style> tag inside my HTML
code. It works fine in all the browsers I tested, but it seems to be more
of
a hack than a valid solution.

Of course I did some research, but without success. So here is my question
to you:

Do the HTML+CSS standards allow <style> tags inside the <body>?


<disclaimer>
I'm not a CSS or HTML guru so the following may contain errurs.
</disclaimer>

I did a test page with a <style> block in the <head> and another within the
<body> then tried to validate it as HTML4.01-Strict and received the
following results:

===================
Line 20, column 22: document type does not allow element "STYLE" here

<style type="text/css">

The element named above was found in a context where it is not allowed. This
could mean that you have incorrectly nested elements -- such as a "style"
element in the "body" section instead of inside "head" -- or two elements
that overlap (which is not allowed).
===================

Having said that, the browsers I use seem to allow <style> within the <body>
and the DOM explorer of Firefox1.0.6 shows two <style> blocks within the
<head> rather than one in the <head> and one in the <body>.

If you want to add styles within the <body> you use inline styles.
eg: <p style="font-style:italic">This is ITALIC, if your font supports
it.</p>
Aug 2 '05 #13
> If you want to add styles within the <body> you use inline styles.
eg: <p style="font-style:italic">This is ITALIC, if your font supports
it.</p>


Thank you, but this is exactly what I am trying to avoid. Imagine a table
with a few thousands of cells - the size of the HTML code would explode if
I
provided a complete inline style definition for each and every one of
them...

The HTML validator that comes with Dreamweaver also seems to disapprove
<style> within the body - guess I'm gonna have to live with that :-(

Regards,
Matthias

Aug 2 '05 #14
Matthias Hullin:
As I need some more styles than the standard stylesheet provides,
I just added a <style> tag inside my HTML code.


That's wrong. Ask the person responsible for the site-wide stylesheet to
(review and) include your code, if you don't have write access to it
yourself.
Aug 2 '05 #15
Matthias Hullin wrote:
If you want to add styles within the <body> you use inline styles.
eg: <p style="font-style:italic">This is ITALIC, if your font supports
it.</p>

Thank you, but this is exactly what I am trying to avoid. Imagine a table
with a few thousands of cells - the size of the HTML code would explode if
I
provided a complete inline style definition for each and every one of
them...


You possibly don't have to. You can apply styles using a variety of
selectors, including ids and classes, as well as inheritance. There
is often functionally no difference where you put the style element as
many browsers will simply move it to the head anyway - but it is
invalid HTML to put it in the body and you can't guarantee that all
browsers will tolerate it.

If you are having difficulty minimising your style code, post some
brief examples of what you have with an explanation of what you expect
it to do (not the usual 'this doesn't work') and you will probably get
some advice on how to apply it efficiently.

[...]

--
Rob
Aug 2 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by ad | last post: by
nathj
5 posts views Thread by nathj | last post: by
5 posts views Thread by Jean Pierre Daviau | last post: by
5 posts views Thread by JackRbt | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.