【问题标题】:can respond.js process an internal stylesheetrespond.js 可以处理内部样式表
【发布时间】:2014-06-27 22:36:38
【问题描述】:

我使用modernizer.js & respond.js在IE8上实现媒体查询。

我对我的页面(HTML 和 Javascript)进行了编码,例如:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>Modernizr test page</title>
    <style type="text/css" media="all">
        @media (max-width: 500px) {
            body {
            background-color: blue;
            }
        }
    </style>
  </head>
  <body>
    Modernizr test page<br>

    <script src="modernizr.custom.js"></script>
    <script>
        Modernizr.load({
            test: Modernizr.mq('only all'),
            nope: '//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.js'
        });
    </script>
    </body>
</html>

没有用。


然后我将代码更改为:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>Modernizr test page</title>
    <link rel="stylesheet" href="myStylesheet.css">
  </head>
  <body>
    Modernizr test page<br>

    <script src="modernizr.custom.js"></script>
    <script>
        Modernizr.load({
            test: Modernizr.mq('only all'),
            nope: '//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.js'
        });
    </script>
    </body>
</html>

还有一个单独的 CSS 文件“myStylesheet.css”:

@media (max-width: 500px) {
    body {
        background-color: blue;
    }
}

它奏效了。


我快速浏览了respond.js Github page,但找不到任何关于不支持内部样式表引用的内容。

我错过了什么吗?

【问题讨论】:

  • 嗨,好问题。我也有同样的行为,并且对此很感兴趣。

标签: html css internet-explorer-8 modernizr respond.js


【解决方案1】:

似乎我们必须在任何内部或外部样式之后连接 respond.js。那么它应该可以工作了!

【讨论】:

  • 如果你看看我的例子。 Respond.js 添加为代码中的最后一件事(就在结束 &lt;/body&gt; 标记之前)
猜你喜欢
  • 1970-01-01
  • 2011-12-05
  • 1970-01-01
  • 2021-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-14
相关资源
最近更新 更多