html5shiv not working in IE8?

前端 未结 3 1378
遥遥无期
遥遥无期 2021-01-11 21:05

I can\'t get styles to pick up in IE8 with HTML5 elements. I\'ve trawled stackoverflow and Google, no suggestions I\'ve tried work.

I started with a much more elabor

相关标签:
3条回答
  • 2021-01-11 21:39

    Move HTML5Shiv’s script element to head section, before all other style and script elements.

    0 讨论(0)
  • 2021-01-11 21:40

    Move the shiv before the style declarations.

    To increase performance in modern browsers, you might want to use conditional comments for the shiv.

    <!doctype html>
    <html>
        <head>
            <meta http-equiv="X-UA-Compatible" content="IE=edge" />
            <meta charset="UTF-8" />
            <title>Template</title>
    
            <!--[if lt IE 9]>
                <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
            <![endif]-->
    
            <style type="text/css">
                header {
                    display: block;
                    border:1px solid red;
                }
            </style>
        </head>
        <body>
            <header>
                HTML5 HEADER
            </header>
        </body>
    </html>
    
    0 讨论(0)
  • 2021-01-11 21:54

    I had a similar problem, but my issue had to do with IE conditional comment syntax.

    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>HTML5 Shim Test</title>
    
        <style>
            nav ul { font-weight: bold; }
            /* the links wont be bold in IE8 unless the shim is working */
        </style>
    
        <!--[if lt IE 9] >
        <script src="html5shiv.js"></script>
        <![endif]-->
    
    </head>
    <body>
        <nav>
            <ul>
                <li><a href="#">Link 1</a></li>
                <li><a href="#">Link 2</a></li>
                <li><a href="#">Link 3</a></li>
            </ul>
        </nav>
    </body>
    </html>
    

    Did you notice the space between ] and > in <!--[if lt IE 9] >? I didn't either...for a very long time. Remove the space and everything works great.

    Also, it's worth mentioning that the HTML5 Shim project page does say that the shim needs to be in the <head>, but it can come after your stylesheets:

    "It must be included before the <body> element (i.e. in the <head>) but doesn't matter if it appears before or after the CSS - but for the sake of performance, it would make better sense to include the CSS first then this script." via https://code.google.com/p/html5shim/

    0 讨论(0)
提交回复
热议问题