CSS3 media query not working

落花浮王杯 提交于 2020-01-05 12:11:47

问题


I am using the following media queries on my website.

<link rel="stylesheet" href="web.css" media="only screen and (min-device-width : 1025px)" />
<link rel="stylesheet" href="ipad.css" media="only screen and (min-device-width : 768px) and (max-device-width : 1024px)" />

My intention here was to have different stylesheets for different devices. (For now I want to support only desktops and ipads).

But when I load the website on my desktop using Firefox (Version 8) or Chrome (Ver: 15.0.874.106) it downloads both the CSS files (both web.css and ipad.css).

I am not too sure what is the wrong with my code. Can someone help me with this.


回答1:


for Desktop you have to write min-width instead of min-device-with like this:

<link rel="stylesheet" href="web.css" media="only screen and (min-width : 1025px)" />
<link rel="stylesheet" href="ipad.css" media="only screen and (min-device-width : 768px) and (max-device-width : 1024px)" />



回答2:


IT might not work, but try changing the values down a number:

<link rel="stylesheet" href="web.css" media="only screen and (min-device-width : 1024px)" />
<link rel="stylesheet" href="ipad.css" media="only screen and (min-device-width : 768px) and (max-device-width : 1023px)"



回答3:


Browsers that support the use of media queries will download all of your stylesheets regardless of which one it needs to display unfortunately.

These queries will give you two different layout handles based on resolution, rather than device, but both stylesheets will always be downloaded.

media="screen and (min-width: 768px) and (max-width: 1024px)"
media="screen and (min-width: 1025px)"


来源:https://stackoverflow.com/questions/8079036/css3-media-query-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!