This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Stylesheets > September 2005 > style tag with CDATA... @import...





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author style tag with CDATA... @import...
Xah Lee

2005-09-10, 7:27 pm

what does it mean when a style tag gives something like the following?

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

is this standard?

Xah
xah@xahlee.org
=E2=88=91 http://xahlee.org/

Spartanicus

2005-09-10, 7:27 pm

"Xah Lee" <xah@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
Spartanicus

2005-09-10, 7:27 pm

Chris Morris <c.i.morris@durham.ac.uk> wrote:

>
><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.
>
>
>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
Gus Richter

2005-09-10, 7:27 pm

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
> xah@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
Spartanicus

2005-09-10, 7:27 pm

Spartanicus <invalid@invalid.invalid> wrote:

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


Brainfart, sorry.

--
Spartanicus
Robi

2005-09-10, 7:27 pm

Gus Richter wrote in message news:5r6dnVC2vcFfjr7eRVn-rA@golden.net...
> Xah Lee wrote:
>
> 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>

Andy Dingley

2005-09-10, 11:16 pm

On Sat, 10 Sep 2005 16:12:27 GMT, Spartanicus <invalid@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.

Gus Richter

2005-09-10, 11:16 pm

Robi wrote:
> Gus Richter wrote in message news:5r6dnVC2vcFfjr7eRVn-rA@golden.net...
>
>
>
> 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 & 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
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews