Respond.js和Modernizr没有在IE8上进行媒体查询

时间:2012-11-09 14:47:14

标签: jquery modernizr polyfills

我有一个博客,我试图在所有浏览器中使用bootstrap作为项目的主干。我使用Modernizr和Respond强制IE响应媒体查询,但由于某种原因脚本无法正常工作。我是以不正确的顺序放置它们还是覆盖它们的另一个JS脚本?任何帮助将不胜感激。

    <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/library/css/bootstrap.min.css">
    <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/library/css/bootstrap-responsive.min.css">
    <link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:700' rel='stylesheet' type='text/css'>
<script src="<?php echo get_template_directory_uri(); ?>/library/js/modernizr.full.min.js"></script>
<script src="https://raw.github.com/scottjehl/Respond/master/respond.min.js"></script>          
    <!-- HTML Shim - Enables usage of all HTML5 elements in Internet Explorer -->
    <!--[if lt IE 9]>
        <script src="https://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script>window.jQuery || document.write(unescape('%3Cscript src="<?php echo get_template_directory_uri(); ?>/library/js/libs/jquery-1.7.1.min.js"%3E%3C/script%3E'))</script>

    <!-- Selectivizr - Enable CSS3 selectors for IE 6-8 -->
    <!--[if (gte IE 6)&(lte IE 8)]>
        <script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/library/js/libs/selectivizr-min.js"></script>
    <![endif]-->
    <script src="<?php echo get_template_directory_uri(); ?>/library/js/bootstrap-tooltip.js"></script>
    <script src="<?php echo get_template_directory_uri(); ?>/library/js/bootstrap-popover.js"></script>
    <script src="<?php echo get_template_directory_uri(); ?>/library/js/bootstrap-typeahead.js"></script>
    <script src="<?php echo get_template_directory_uri(); ?>/library/js/site.js"></script>
    <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
    <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>">
    <!-- wordpress head functions -->
    <?php wp_head(); ?>
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">
</head>

3 个答案:

答案 0 :(得分:5)

尝试移动

<script src="https://raw.github.com/scottjehl/Respond/master/respond.min.js"></script>

要追踪你的最后一个样式表链接(你可能已经错过了它,但底部有一个)。

答案 1 :(得分:3)

添加respond.js不会修复媒体查询。我使用了css3-mediaqueries.js并编写了我的媒体查询:

    @media screen and (min-width: 768px) and (max-width: 979px) {
      // css;
    }

而不是:

    @media (min-width: 768px) and (max-width: 979px) {
      // css;
    }

答案 2 :(得分:2)

同样的问题。我发现这是我的加载序列问题,因为我首先编写CSS内联,所以它看起来像

<script type="text/javascript" src="js/respond.min.js"></script>

<link rel="stylesheet" type="text/css" href="style.css" media="screen" />

应该是

<link rel="stylesheet" type="text/css" href="style.css" media="screen" />

<script type="text/javascript" src="js/respond.min.js"></script>

总是在脚本之前调用样式表!

相关问题