html - respond.js 可以处理内部样式表

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

我使用 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但找不到任何关于不受支持的内部样式表引用的提及。

我错过了什么吗?

最佳答案

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

关于html - respond.js 可以处理内部样式表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21464582/

相关文章:

javascript - 拖放功能在触摸设备中不起作用?

iframe - 在 IE8 开发者工具中的 IFrame 中检查?

javascript - 如何使用指针事件仅对滚动事件使用react?

html - 使用网格单元格对齐在 div 内跨度

文本溢出 CSS 截断

jquery - CSS 或 jQuery 将 div 定位在视口(viewport)底部

javascript - 粘性导航问题 - "position: fixed"可能未生效

css - IE8位置错误

html - 导航菜单在 IE8 中无法正常工作

javascript - 在 firefox 中使用 javascript 设置元素样式