问题
I have a problem with using HTML5 elements in Internet Explorer 7 and up (not testing IE6). I know that by default, IE refuses to recognize common HTML5 elements like "article" or "header" without the use of a Javascript "shiv". I've used modernizr (http://www.modernizr.com) to force IE to recognize these elements to that I can apply CSS styles to them. So far so good.
The problem now is that the application uses Javascript to fetch certain HTML fragments (containing HTML5 markup) and inserts them into the document at run-time. On all other browsers, this works flawlessly, but in IE, elements inserted at runtime can't be styled with CSS.
Here's an example of the chunk of markup that I'm injecting into the page:
Title
Text
I've tested my theory by replacing the article tag by a common div, which seems to solve the problem for now, at the expense of semantic markup. But I'd like to know if there are any more future-proof workarounds.
回答1:
Maybe this will help: http://jdbartlett.github.com/innershiv/
innerShiv is a function which takes your HTML string, adds it to a hidden document-appended element in IE, and returns an IE-safe document fragment or collection.
回答2:
I think I'd just use a
The purpose of semantic markup is to help the search engines understand what the page content is about. Dynamic content like this which is loaded after the main page load may not be seen by the search engines, so semantic markup is perhaps a moot point.
回答3:
By default, the HTML5 elements like header, article etc are inline.
In your CSS file, you should set display: block rule for them.
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section
{
display: block;
}
Hope this helps you!
来源:https://stackoverflow.com/questions/4849219/html5-elements-in-internet-explorer-runtime-insertion