473,382 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

<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 32637
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 vão. 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kai Grossjohann | last post by:
I have a table which contains a top-aligned table cell: .... <tr style="height:40"> ... <td colspan="1" rowspan="2" align="left" valign="top" style="overflow:hidden;">...
9
by: Julia Briggs | last post by:
How do I construct a <iframe> or equivalent for FireFox/NS browsers, inside a screen centered <div> tag? Can it be done?
6
by: Ken Varn | last post by:
I want to add my own custom <STYLE> section in the <HEAD> section of my ASP.NET page within a custom control. Can someone tell me how I can have my custom control add tags to the <HEAD> section of...
2
by: ad | last post by:
I use vs2005 to develop web application. I have used the new feature of master page of VS2005, and I have put some <stylein the master page. But I want to override some Style sheet in the content...
5
nathj
by: nathj | last post by:
Hi All, I'm working on a new site that has a two column layout underneath a title bar. If you check out: http://www.christianleadership.org.uk/scratch/mainpage.php using IE or Opera you will...
7
by: Amzul | last post by:
hello all. can someone tell if its possible to put <strong> inside the value? whats the right syntax? and another Q is it possible to applay new style to a form i mean i want to disable all...
5
by: Jean Pierre Daviau | last post by:
Hi to every one. How can I manage to write this kind of css in a style="". img { width: 150 px; height: 100 px; text-align: center; }
5
by: JackRbt | last post by:
I have a footer in a separate file that gets included via PHP, and that has its own styles. That means the footer's <style> is declared in the body, rather than as an element in <head>. Is there...
1
by: Lagon666 | last post by:
How can i get css contains of an element. When i use alert(document.getElementById('mydiv').style.opacity) it will return empty. <style> #mydiv{ background:#000000; opacity:0.4; } </style>
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.