I have the following HTML code, where I would like to format with css a data format (coming from xml) which can\'t be changed.
I have to give different styles to el
Your HTML is not valid. If you run it through a validator it spits out errors because it doesn't like the named embedded XML tags.
According to the HTML/XML Task Force Report:
When an HTML5 parser encounters unfamiliar markup, it assumes that such markup is an erroneous attempt to generate well-defined HTML5. Consequently, it applies error correction strategies which result in a DOM representation that can differ radically from the DOM that an XML parser would have produced. In particular, open elements may end prematurely and additional elements may be opened.
The practical result is that a “naked” XML island in an HTML5 document will not reliably produce anything that resembles the DOM one would expect from casual inspection of the XML island.
So Chrome is well within its rights to screw up here, 'cause technically you did it first. Of note is how (in my Chrome browser) all the elements are green (http://jsfiddle.net/qJMWg/) - which suggests that for some reason that all thing they're nested in a big <f type="h2">
element. That is of note because HTML does contains a <b>
and <s>
tag, so <f>
is the first invalid one it encounters.
If we change the styles for that f\[type=h2\] rule (http://jsfiddle.net/qJMWg/1/) it affects everything - which is consistent with the idea that somehow Chrome is interpreting this XML structure incorrectly. To Chrome's CSS engine (despite what the developer tools is telling us) this somehow looks like this:
<b>
<s>
<f type="h2">Title</f>
<f type="p">Paragraph</f>
<f type="speech">Dialgoue</f>
<f type="other" br="true">Other</f>
<f type="p">Paragraph</f>
<f type="p">Paragraph</f>
</s>
</b>
For some unknown reason, Chrome is rather strict on HTML tags thus the CSS rule won't work well in the said browser.
A suggestion though, why don't you style the XML instead?
Changing attr name will help you , andi have no idea why
<f custom="p">Paragraph</f>
<f custom="speech">Dialgoue</f>
<f custom="other" br="true">Other</f>
<f custom="p">Paragraph</f>
<f custom="p">Paragraph</f>
<style type="text/css">
f[custom=h2] {
color: green;
}
f[custom=p] {
color: blue;
}
f[custom=speech] {
color: yellow;
}
f[custom=other] {
color: gray;
}
</style>