By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,780 Members | 1,550 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,780 IT Pros & Developers. It's quick & easy.

style tag with CDATA... @import...

P: n/a
what does it mean when a style tag gives something like the following?

<style type="text/css" media="screen,projection">/*<![CDATA[*/ @import
"/style/monobook/main.css"; /*]]>*/</style>

is this standard?

Xah
xa*@xahlee.org
http://xahlee.org/

Sep 10 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
"Xah Lee" <xa*@xahlee.org> wrote:
what does it mean when a style tag gives something like the following?

<style type="text/css" media="screen,projection">/*<![CDATA[*/ @import
"/style/monobook/main.css"; /*]]>*/</style>

is this standard?


Something like that is required for XHTML served as XHTML, but afaik the
syntax used there is wrong, see http://www.hixie.ch/advocacy/xhtml

--
Spartanicus
Sep 10 '05 #2

P: n/a
Spartanicus <in*****@invalid.invalid> writes:
"Xah Lee" <xa*@xahlee.org> wrote:
what does it mean when a style tag gives something like the following?

<style type="text/css" media="screen,projection">/*<![CDATA[*/ @import
"/style/monobook/main.css"; /*]]>*/</style>

is this standard?
Something like that is required for XHTML served as XHTML,


<style type="text/css" media="screen,projection">
@import "/style/monobook/main.css";
</style>
would be better, surely, even for XHTML as XHTML?

Personally I'd rather use that [1] and risk breaking the page slightly in
Netscape 1 and earlier (as if XHTML and half of HTML 4 wouldn't
confuse them enough), than have the unreadable and unmemorable nested
comment that the various specifications require between them.
but afaik the syntax used there is wrong, see
http://www.hixie.ch/advocacy/xhtml


Indeed. It's not just decade-old cargo cult baggage, it wouldn't even
have worked properly in the few browsers it was necessary for.

So, I suppose in answer to the OP's question, if you see that in the
style tag it means the author was confused.

[1] Actually, I'd just use <link>, and deal with the NS4/IE4 hiding
another way.

--
Chris
Sep 10 '05 #3

P: n/a
Chris Morris <c.********@durham.ac.uk> wrote:
>what does it mean when a style tag gives something like the following?
>
><style type="text/css" media="screen,projection">/*<![CDATA[*/ @import
>"/style/monobook/main.css"; /*]]>*/</style>
>
>is this standard?


Something like that is required for XHTML served as XHTML,


<style type="text/css" media="screen,projection">
@import "/style/monobook/main.css";
</style>
would be better, surely, even for XHTML as XHTML?

Personally I'd rather use that [1] and risk breaking the page slightly in
Netscape 1 and earlier (as if XHTML and half of HTML 4 wouldn't
confuse them enough), than have the unreadable and unmemorable nested
comment that the various specifications require between them.
but afaik the syntax used there is wrong, see
http://www.hixie.ch/advocacy/xhtml


Indeed. It's not just decade-old cargo cult baggage, it wouldn't even
have worked properly in the few browsers it was necessary for.


I think that you are confusing the quoted CDATA construct with the old

<style type="text/css">
<!--
foo{color:white}
-->
</style>

construct meant to prevent very old and by now unusable browsers from
rendering the content of the style and/or script element.

The CDATA construct is based on something else specific to XHTML served
as such IIRC, read Hixie's article for the specifics.

--
Spartanicus
Sep 10 '05 #4

P: n/a
Xah Lee wrote:
what does it mean when a style tag gives something like the following?

<style type="text/css" media="screen,projection">/*<![CDATA[*/ @import
"/style/monobook/main.css"; /*]]>*/</style>

is this standard?

Xah
xa*@xahlee.org
http://xahlee.org/


Yes, it is to mark a section as CDATA as described in XHTML 1.0 Appendix
C, however, he is commenting out the CDATA marked section tags.

--
Gus
Sep 10 '05 #5

P: n/a
Spartanicus <in*****@invalid.invalid> wrote:
I think that you are confusing the quoted CDATA construct with the old


Brainfart, sorry.

--
Spartanicus
Sep 10 '05 #6

P: n/a
Gus Richter wrote in message news:5r********************@golden.net...
Xah Lee wrote:
what does it mean when a style tag gives something like the following?

<style type="text/css" media="screen,projection">/*<![CDATA[*/ @import
"/style/monobook/main.css"; /*]]>*/</style>

is this standard?


Yes, it is to mark a section as CDATA as described in XHTML 1.0 Appendix
C, however, he is commenting out the CDATA marked section tags.


I thought it should be like this using all the "hacks" needed for older
browsers:

<style type="text/css" media="screen,projection"><!--/*--><![CDATA[/*><!--*/
@import "/style/monobook/main.css";
/*]]>*/--></style>

Sep 10 '05 #7

P: n/a
On Sat, 10 Sep 2005 16:12:27 GMT, Spartanicus <in*****@invalid.invalid>
wrote:
The CDATA construct is based on something else specific to XHTML served
as such IIRC, read Hixie's article for the specifics.


Hixie's article is a deliberate bit of poking fun at XHTML - the idea of
how to deal "neatly" with "hiding CSS" when you choose to serve
XHTML-as-XML to an ancient browser, despite the fact you're playing
merry hell with its accept: header.

XHTML needs some careful handling of _scripts_ with a <![CDATA[ ... ]]>
section. But for CSS, just serve rthe stuff and don't worry about it.

Sep 10 '05 #8

P: n/a
Robi wrote:
Gus Richter wrote in message news:5r********************@golden.net...
Xah Lee wrote:
what does it mean when a style tag gives something like the following?

<style type="text/css" media="screen,projection">/*<![CDATA[*/ @import
"/style/monobook/main.css"; /*]]>*/</style>

is this standard?


Yes, it is to mark a section as CDATA as described in XHTML 1.0 Appendix
C, however, he is commenting out the CDATA marked section tags.

I thought it should be like this using all the "hacks" needed for older
browsers:

<style type="text/css" media="screen,projection"><!--/*--><![CDATA[/*><!--*/
@import "/style/monobook/main.css";
/*]]>*/--></style>


You have some errors and omissions in your code sample.

You are thinking of pre-level 4 browsers that did not understand the
style element, where you would use the HTML comment <!--...--> to
comment out the _embedded_ stylesheet section so that it would not be
set as text. This is not needed for today's browsers. Anyone using
vintage browsers and/or Lynx are probably used to seeing such junk. If
you care enough, then you should not be using XHTML anyway and use HTML
where it is OK to comment out the CSS declarations for the CSS
challenged browsers.

What the original code segment showed is using CSS comment /*...*/ to
comment out the CDATA marked opening tag /* <![CDATA[ */ and the
CDATA marked closing tag /* ]]> */ for some reason, likely that the
author realized that they are not needed for his _external_ stylesheets,
wasn't quite sure and left it there just in case he did need the CDATA
marked tags after all, in which case he would remove the CSS comments.

The following is what XHTML 1.0 Appendix C says on the subject:

Script and Style element contents must be wrapped within a CDATA marked
section to avoid expansion of entities < and & as start of markup and
not to recognize &lt; and &amp; as < and & respectively.

<script>
<![CDATA[
... unescaped script content ...
]]>
</script>

An alternative is to use external script and style documents.

For compatibility with existing HTML 4 user agents, use external style
sheets or external script if either uses < or & or ]]> or --.
Note: The historical practice of "hiding" scripts and style sheets
within comments for backward comptibility is likely to not work as expected.

--
Gus
Sep 11 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.