|Opera @import fails with type application/xhtml+xml|
Is it me, is it a bug, or is it by design?
| 2:13 pm on Aug 26, 2004 (gmt 0)|
Sorry if this is the wrong forum for this post. A browser query, with XHTML, CSS and a little PHP but this seemed to be the right place.
I cannot get Opera 7.51 to @import stylesheets when the document has a content-type of application/xhtml+xml.
Here's the code that's involved (I've omitted most tags in the post to save space)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="en" lang="en">
<link rel="stylesheet" type="text/css" title="Standard" href="http://XXX/themes/default/style.css" />
I use this technique to deliver extra stylesheets to more modern browsers.
Everything works great. Pretty much every graphical browser loads the linked stylesheet, and only the more modern browsers read the imported style sheets (i.e. not NN4).
When I set the content-type to text/html everything works fine. If on the other hand I set it to application/xhtml+xml, Opera 7.51 ignores the @import statements (and so only the linked stylesheets load). I haven't tried other versions of Opera yet, but everything is fine in Firefox.
I'm checking $_SERVER["HTTP_ACCEPT"] and if the browser indicates that it will accept xhtml I set the following
@header("Content-Type: application/xhtml+xml; charset=ISO-8859-1");
Can I not rely on importing stylesheets with a document set as application/xhtml+xml or am I misunderstanding something?
Should I serve every page as text/html? (I hate myself for saying this - but at least it works).
Should I be using a different method of delivering stylesheets?
I could use a single stylesheet and resort to css hacks but I want to avoid that.
If anyone could duplicate this I'd be grateful to hear about it - I think I'm going mad.
Also, this is my first post on Webmaster World (hello everyone) so be kind. ;)
| 2:28 pm on Aug 26, 2004 (gmt 0)|
Welcome to WebmasterWorld [webmasterworld.com], mrobinson!
I haven't had a chance to test this fully, but have you tried removing the CDATA comments from around the @import statements? A quick test showed me that an uncommented @import on an XHTML document served as
application/xhtml+xml worked fine in Opera 7.50.
| 2:45 pm on Aug 26, 2004 (gmt 0)|
Thanks for the welcome and for a prompt response.
I've made the changes you suggested and everything is working as it should. The only bug to report is me!
It didn't even occur to me that the CDATA part could be the problem. I stripped out just about everything to get to the bottom of this (yet I trusted the CDATA) lol.
Are the good old <!-- comment --> tags best used to hide the style contents from legacy browsers?
| 3:26 pm on Aug 26, 2004 (gmt 0)|
You could try adding the comments like this:
Which is fairly crazy, but you might have better luck (I haven't tested it in Opera). You could also use a link element as for your first stylesheet, and in that linked stylesheet you place the two @import statements to call the two advanced stylesheets.
If you use standard HTML comments only when serving XHTML as
application/xhtml+xml, then the user agent is supposed to silently remove the contents - so your stylesheets won't load. Using an uncommented style block risks displaying the contents on-screen, but only for very old browsers (read Netscape 2).
| 4:37 pm on Aug 26, 2004 (gmt 0)|
Your suggestion of linking to a stylesheet and then importing from there is an elegant solution and I can't believe it didn't occur to me before (hindsight is wonderful).
I'm looking forward to serving more application/xhtml+xml in the future.