简体   繁体   English

CSS媒体查询不起作用

[英]CSS media query not working

When checking my site on a mobile device (iPhone) it is clear that it is still loading the non mobile stylesheet. 在移动设备(iPhone)上检查我的网站时,很明显它仍在加载非移动样式表。 Here is the code in the header, can someone tell me whats wrong? 这是标题中的代码,有人可以告诉我什么地方不对吗?

<link rel="stylesheet" href="styles.css" type="text/css" /> <link rel="stylesheet" type="text/css" media="only screen and (max-device-width: 480px)" href="styles_mobile.css" />

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

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


<script>

if (screen && screen.width > 480)
document.write('<script type="text/javascript" src="js/jqFancyTransitions.js"><\/script>');

</script>

Any reason why this is not using the "styles_mobile.css" as is intended? 为什么不按预期使用“ styles_mobile.css”?

In any response please be aware that I have limited knowledge of javascript 在任何回复中,请注意,我对javascript的了解有限

I think it needs a meta viewport tag: 我认为它需要一个meta视口标签:

http://www.quirksmode.org/blog/archives/2010/09/combining_meta.html http://www.quirksmode.org/blog/archives/2010/09/combining_meta.html

This means use the device width, not the width that the browser in the device reports, which is bigger. 这意味着使用设备宽度,而不是设备中浏览器报告的宽度,该宽度更大。

Technically, to do media queries by the book you need to add a "media" attribute to the element, or add @media entries to your CSS. 从技术上讲,要按书进行媒体查询,您需要在元素中添加“ media”属性,或在CSS中添加@media条目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM