Google Chrome obeys alternate CSS

So Google Chrome is out. That’s great! It’s really a cool, fast, secure browser.

Unfortunately, it appears to break sites in one very important way: it obeys alternate stylesheets, just as if they were normal, active stylesheets. This breaks sites who print their alternate CSS links after active ones (like mine – for now).

I’ve sent this in as a bug to Google, and i’d recommend that others do the same (select “report bug or broken website” from the page icon to the upper right).

At the moment, the only thing to do is to list alternate stylesheets before active ones, or exclude alternate links altogether.

However, there are (naturally!) problems with each method…

Listing alternate CSS (which would still be obeyed) could still cause style conflicts, if there are any rules which are not contradicted (read: overwritten) by later stylesheets below the alternate ones.

On the other hand, not listing alternate stylesheets disables additional functionality in user agents such as Opera, which allows users to select from a menu what style they’d prefer to view a site in – which is arguably the best, most accessible method of switching stylesheets (if you’re using one of those user agents, that is).

For my money, i believe the former is the best option. This means i may have to do some code “cleaning,” which i should have done anyway. In fact, rather than removing extraneous CSS rules, i’ll be adding rules which do not exist in, say, X.css to Y.css, in order to counteract any style collisions by overwriting them with alternate rules.

Btw, for those who need it, here’s the User Agent string i captured:

Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13

[UPDATE] Matt Wilcox helpfully pointed out that this isn’t exactly a Chrome bug, but a leftover Safari one which has apparently been around for years, according to a decently shrewd Google search. Lesson: test in Safari, even if you think it’s a Practically Perfect Browser.

I have fixed it locally but am waiting for at least a few more hours in order to use this site as an example. Hey, it beats making a quick mock-up. Sort of. (My teachers always thought i was most useful as an example to warn others – well, i do what i can!)

And a big thanks to the great Jeffrey Zeldman for helping get the word out to designers about this. Of course, 99% of people making web sites won’t be affected, but for those of us using alternate styling, it’s a nasty thing to have happen.

[UPDATE 2] To clarify, Safari and Chrome both use the Webkit rendering engine, as well as parts of the Mozilla FIrefox codebase. Not to point fingers or anything. I’m just sayin’ is all.

[UPDATE 3] I couldn’t take it anymore. I fixed things here so there shouldn’t be any issues. I use a browser sniffer to detect the user agent and deliver either modern CSS or a crappy facsimile thereof for older, less standards-compliant user agents. As long as i keep up to date, no problem… of course, the drawback is obvious. I must keep up to date. Anyway, i’ve completely eliminated the alternate styles for both Chrome & Safari, at least until this bug is fixed in the Webkit renderer. In the meantime, i’ll put together a tester page and link it here.

About jeremy

x jeremy jarratt is a blogger, musician, artist, poet, web developer/designer, armchair philosophizer, teller of tales, and gadabout. Also, something he calls a "behavioral artist." (Not sure.) He is currently unemployed, although he has plans. BIG plans. Among the things that he has done for a laugh are minor fractures, cuts, scrapes, and various scabs. Though he's quick to point out that he's no imbecile, we're fairly certain that he thinks the word means some kind of medieval pharmacist. This is his latest home on teh internets - where he stores his swear words, when he's not hurling them at the sun in vain.
Tagged , , , , , , , , . Bookmark the permalink.
  • Pingback: Jeffrey Zeldman Presents : A bug in Google Chrome

  • http://mattwilcox.net Matt Wilcox

    It’s the same bug that Safari has had on my site for years, and continues to have – the on-screen display is completely littered with print-style amends (like placing the URL as generated content after each hyperlink). It’s not unique to Chrome (but highly annoying anyway) – try viewing my site with Chrome or Safari, both will screw up: http://mattwilcox.net/

  • http://jeremyjarratt.com jeremy

    Matt, you’re awesome! I had a nagging feeling that something was amiss. You’re 100% correct, this is a Safari leftover.

  • http://www.aleeya.net erica

    I have also noticed another bug. I tried this in safari, opera, ie, ff and I only see it in Chrome. So far it is only on *gasp* MySpace Pages.

    For an example – http://www.myspace.com/rubblerats

    The text is doubled.. or over emphasized.. I am not sure how to explain it. I cannot remember if that profile is private or not, so I have taken a screenshot and put it on my site http://www.aleeya.net . But, until I get the database back up in about an hour, it will not be up (sorry!).

    And, it is not just on one page.. hundreds of them so far on MySpace seem to have this problem. But then again MySpace code is *cough* something left to be desired and not always correct code.. but the point being all the other browsers read it right including Windows version of Safari.

  • Pingback: 10 Reasons Firefox won’t be worried about Chrome « Boriss’ Blog

  • Pingback: nortypig » Blog Archive » Google Chrome

  • http://jeremyjarratt.com jeremy

    @erica:
    Thanks! That’s pretty weird. I thought it was maybe changing the font-weight, but the closer i look, the more weirded out i get. It does look like the text is doubled! Natch, i reported it too.

    Btw, cool site(s), you seem like a really cool geek!

  • Uday Ramakrishna

    I have also found that both safari and chrome have a problem with nested tables using 100% width. I have a 3 column inner table that gets displayed well in FF and IE but what happens when I see it in Chrome and Safari is utter dismay, there is a javascript that changes content in column 3 based on clicks in column one using innerHMLT. What happens is that the columns are resized and the third column takes the max width. But this does not happen when I use width in pixcel…

  • http://jeremyjarratt.com jeremy

    @Uday: wow, another weird Webkit bug! It’s a good thing the other 99% of this renderer rocks….

  • Pingback: GizmoTechNet » Blog Archive » Chrome Update Part 3 … Alternate CSS Probs?

  • Pingback: Chrome: el navegador de Google comparado con Firefox y Explorer : Blogografia /version beta/

  • http://www.kogmedia.com film fan

    there are so many advantages and features with Chrome, such as it’s speed, for example; now if only they would take care it’s flighty cookie management…

  • http://www.girlgeekette.net erica

    @Jeremy thank you! hehehe me a geek? nah never ;)

  • Pingback: Horus Kol » Chrome - the next generation of browser?

  • Pingback: Pemaquid Crunch: Web Design notes from Portland, Maine » Blog Archive » Chrome could help set the (Web) Standard

  • Pingback: El blog de Jack Román A. » Blog Archive » Exploradores de internet

  • http://www.taxiforrent.com Renju

    I badly need the alternate styling to work on my website. I had written it in a way to check if “Calibri” font is installed, then everything would appear in calibri else would use Tahoma. Its works fine in IE & Firefox. But doesnt in Chrome… :-(. Has somebody found a workaround for this??
    Taxi For Rent

    • http://jeremyjarratt.com jeremy

      @Renju: I haven’t really delved into your site, but why don’t you just put your preferred font in the front of the font-family declaration?

      font-family: Calibri,Tahoma,sans-serif;

      • cheers

        Doesn’t seem like you have answered this question…Here’s my issue:

        I’d like a button inside my HTMl to swap between White and Black versions. I’ve been trying to do this with JQuery/JS but without success.

        I am using “disabled=disabled” for FireFox and this works.

        • http://jeremyjarratt.com jeremy

          cheers, i don’t know what your web site looks like or what method of switching out styles you’re using. I used to use a style switcher but it was a little bulky and reloaded the page so i don’t use it anymore. I’m not really familiar with jQuery as much as i’d like to be, but that would certainly be the way to go.

          I did a rudimentary Google search but i’m still not real sure which jQuery plugin you’re using or what could be a potential cause and/or solution. Unfortunately, even if i knew, i’m just not very good with JavaScript, even in the form of the jQuery library. Perhaps the link to that search might guide you in the right direction. Sorry, but good luck!

  • cheers

    Hi Jeremy,

    Thanks for the quick response. I’ve solved it for my purposes:

    html:

    in main.css use the same styles as you would want in WHITE, not BLACK. This will force the white styles if black is turned off in the WHITE version, but it wont force them in the BLACK version since BLACK comes after WHITE. This was a strange trick, but it worked..

    JQuery: (no plugins)

    jQuery.each(jQuery.browser, function(i, val) {
    if(i=="mozilla"){
    $("head .white").attr("disabled","disabled");
    $("head .black").attr("disabled","");
    } else if ( i=="safari"){
    $("head .black").attr("disabled",false);
    $("head .white").attr("disabled",true);
    $("head .white").attr("rel","alternate stylesheet");
    $("head .black").attr("rel","stylesheet");
    } else if ( i=="ie" ){
    }
    });

    I’m using alternate stylesheet online in Safari (which is also Chrome according to the above each() loop).

    It’s a little hacky but the Internet has provided no real answer to this and this is working great for me in Firefox, Chrome, and Safari. I’ll post a link to the site I did this to when I launch it this week.

    gnite

    • cheers

      i cant post html on your blog sorry =/

      HTML:

      link rel="stylesheet" href="assets/css/style.css"
      link class="black" type="text/css" rel="stylesheet" href="assets/css/black.css" title="black"
      link class="white" type="text/css" rel="stylesheet" href="assets/css/white.css" title="white"