views:

72

answers:

3

(The question below is hypothetical, but for reading convenience I'll ask as if I'm actually doing it)

I'm building a site in HTML 5. Unfortunately, IE doesn't support HTML5 elements like "header" and "nav". I was hoping it would treat them like generic "div"'s, but it doesn't. It simply acts as if they aren't there (meaning no CSS is applied to them).

I'd like to fix this by serving IE some dynamically transformed HTML. I'll just use the regular string replacement functions (of PHP, not that it matters) to replace all occurences of

<header>

with

<div class="header>

and so forth (an I'll transform the CSS accordingly). This should be fine, but what about this:

<header class="foo">

With the simplest replace code, this would become

<div class="header" class="foo">

Is that legal in HTML? And will the attribute then end up being "header foo" or just one of them?

(Yes, I do know that the normal way to get multiple classes is

<div class="header foo">

)

+6  A: 

No, you can only have one class attribute - like this:

<div class="header foo">

If you have two or more class attributes, I think it just uses the first one.

Greg
One class attribute, but multiple classes applied to the same element. This would be what you're after.
thismat
Finding the part of the spec that *says* you can't have 2 is surprisingly difficult... I guess the DTD <!ATTLIST doesn't show any repetition... if that's even allowed...
Greg
Yeah, it's kind of taken as read just by the fact that there *is* a DTD: neither SGML nor XML, the standards on which HTML and XHTML build, allow multiple attributes of the same name.
bobince
+2  A: 

If this is processed as XHTML it will be not-well-formed and throw an error and I would expect any conformant HTML parser to do this.

peter.murray.rust
I'll have to test this to be sure, but are you sure it actually throws an exception and doesn't just either balk on it or select the one closest to the content?
thismat
+1  A: 

While it does rely on the client having JavaScript enabled, there is a method to get IE to work more properly with the new HTML5 elements:

http://remysharp.com/2009/01/07/html5-enabling-script/

HorusKol
Very interesting and helpful. I'll try that (though I will have to convince somebody else to let the site go kaput in IE without javascript).
Bart van Heukelom
it's always a problem with stuff like this... comes down to exactly how many users are there with old IE and no javascript compared to all the rest of you userbase...
HorusKol