我使用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页面,但没有发现任何提到的关于不支持内部样式表引用的内容。
我错过了什么吗?
发布于 2014-06-27 14:36:38
似乎我们必须在任何内部或外部样式之后连接respond.js。那就行了!
https://stackoverflow.com/questions/21464582
复制相似问题