html5 runtime原理,HTML5 elements in Internet Explorer: runtime insertion

问题

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

placeholder

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

and live with it.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值