问题
I'm experiencing frustrating situations with IE8 lately. It's the weirdest thing. I had previously working code stop working. It seems to be happening when I'm using HTML5 tags such as header
, footer
, article
and nav
to name a few, being used with their counterpart CSS selectors in my external CSS stylesheet. The problem is: all of a sudden the CSS styles are no longer being applied to my markup. It's like I have no stylesheet at all.
I've made sure that I'm not getting any 404 errors as well as no JavaScript errors.
I've also checked the DOCTYPE
to make sure that my HTML document is in standards mode and the browser even states this is the case.
Also, as I've understood, even though the browser doesn't necessarily view the HTML5 tags as special (like most modern browsers do) it won't tamper with them and they should still be able to be usable in the CSS stylesheet with their respective selectors.
At least that's the impression I got from this other Stackoverflow post: https://stackoverflow.com/a/7801476/295019
Was that always the case or have I been wrong about it the whole time.
I figured I should be able to use HTML5 tags in my code or what's the point of using it if my code just fails. It is in my best interests to build websites that work on IE8 given that quite a bit of people use it (i.e. my clients still ask for their pages to work on it.)
I should also state at this point that I work on Mac and test on an virtual machine version of Windows 7 running on VirtualBox with IE8. Maybe that has something to do with my problems. However, I have restarted my machine several times in the hope that it will work. I've also made sure that Flash is installed and the installation is not corrupt (to the best of my knowledge.)
Does anyone have any idea what's going? Or experienced similar problems?
Any help would be greatly appreciated.
回答1:
Unfortunately, the impression you've got that IE8 works with HTML5 elements is incorrect. IE8 does not work properly with elements like <section>
or <header>
. Using these elements in a page will cause major issues for IE8.
The good news is that there is, however, a simple fix for this problem.
The fix is a script called html5Shiv.
This script uses a handful of Javascript hacks to make HTML5 elements work in old versions of IE. (that is, it just stops them from breaking the page -- it obviously doesn't add the new HTML5 features, so don't expect <canvas>
to suddenly burst into life!)
Simply add this script to the top of your page and you'll be fine.
Another option is a script called Modernizr. This includes the html5Shiv functionality, and also adds another layer of compatibility checking, which can be very beneficial if you're trying to make a modern site but still support old browsers.
Hope that helps.
回答2:
this might help u:
<!--[if lt IE 9]>
<script>
document.createElement('header');
document.createElement('nav');
document.createElement('section');
document.createElement('article');
document.createElement('aside');
document.createElement('footer');
document.createElement('hgroup');
</script>
<![endif]-->
http://www.nickyeoman.com/blog/html/118-html5-tags-in-ie8
回答3:
IE8 doesn't support HTML5 markup. If you want to get rid of your head ache I'll suggest you use a javascrip library to make older browser suport your new html code. Like modernizr http://modernizr.com/
来源:https://stackoverflow.com/questions/13094754/css-styles-not-applied-when-using-html5-selectors-has-something-changed-about-t