IE 5 Mac class attribute with space bug

Crazy Mac IE 5 bugs with the HTML class attribute: If you have a space after any class in the attribute, it will treat any CSS class selector that contains that string at its beginning as a match for the element. For the example:

<html class="doc foo">
<title>Test</title>
<style>
.doca{
    background: green;
}
.fooa{
    background: blue;
}
.foo{
    color: white;
}
.doca .foo{
    color: orange;
}
</style>
<p>Test</p>
<p class="foo">Foo</p>

the background will be green and the text will be white. The foo element will be orange. This will be the case if the class is just doc as well. Without the foo in the class, the background will be white and the text will be black, like in other browsers. With a space after foo, the background will be blue.

If you have a leading space in the class (class=" doc") or it is just a space (class=" "), every single class selector in the sheet will match. For the example, the background would be blue, text white, and foo element orange.

This was causing my site to white-screen in the browser and was very hard to find. And yes, I’m crazy for even testing in IE 5 today.