在Nexus 7 2013上更改方向时,CSS媒体查询无法正常工作

时间:2013-11-17 03:37:44

标签: css3

我目前正在笔记本电脑,台式机和Nexus 7 2013上测试CSS媒体查询。 除Nexus 7外,它们在台式机和笔记本电脑上都能正常工作。 当我更改方向时,样式不适用,除非我刷新页面。 例如:将设备保持在纵向模式时,页面正常。 当我以横向模式转动时,页面会中断。但是,当我刷新页面时,它会加载横向样式。 我不确定我做错了什么。

这是我的代码:

HTML:

    <!DOCTYPE HTML>

<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Title</title>
<link rel="stylesheet" media="screen" href="styles.css">
<body>

Content goes here!

</body>
</html>

CSS:

    /*iPhone PORTRATE*/
@media screen and (max-width:321px) and (min-width:3px){
html{background-color:yellow;}}

/*iPhone LANDSCAPE*/
@media screen and (max-width:480px) and (min-width:322px){
html{background-color:cyan;}}

/*533px*/   
@media screen and (max-width:533px) and (min-width:481px){
html{background-color:pink;}}

/*iPhone 5 LANDSCAPE*/
@media screen and (max-width:568px) and (min-width:534px){
html{background-color:green;}}

/*Resolutions bellow 800px must be tested on specific devices*/

/*600 px - Nexus 7 2013 portrait*/
 @media only screen and (max-device-width : 600px) and (min-device-width : 569px) and (orientation : portrait){
html{background-color:orange;
 }}

/*960 px - Nexus 7 2013 Landscape*/
@media only screen and (max-device-width : 960px) and (min-device-width : 601px) and (orientation: landscape){
html{background-color:red;
}}

/*Desktop and laptop*/

/*800px*/
@media screen and (max-width:800px) and (min-width:601px){
html{background-color:grey;
}}

/*1024px*/  
@media screen and (max-width:1024px) and (min-width:961px){
html{background-color:black;
}}

/*1152px */ 
@media screen and (max-width:1152px) and (min-width:1025px){
html{background-color:blue;
}}

/*1280px*/
@media screen and (max-width:1280px) and (min-width:1153px){
html{background-color:brown;
}}

/*1366px*/
@media screen and (max-width:1366px) and (min-width:1281px){
html{background-color:black;
}}


/*1440px*/
@media screen and (max-width:1440px) and (min-width:1367px){
html{background-color:purple;
}}

/*1600px*/
@media screen and (max-width:1600px) and (min-width:1441px){
html{background-color:lime;
}}

/*1776px*/
@media screen and (max-width:1776px) and (min-width:1601px){
html{background-color:silver;
}}

/*1920px*/
@media screen and (max-width:1920px) and (min-width:1777px){
html{background-color:chocolate;
}}

1 个答案:

答案 0 :(得分:1)

我更喜欢只使用“max-width”和“min-width”,因为这是针对Viewport而不是设备。这样,当您旋转设备时,视口会更改,加载的媒体查询也会更改。

另外我相信你有太多的媒体查询,可能其中一些是干扰。

忘记不同类型的设备,只考虑分辨率。现在你不知道1024px设备是高端手机,普通平板电脑还是小型台式机。 或者,如果768是平板电脑肖像或手机风景。

拥有更少的断点,并确保您的设计适合每个媒体查询的最低部分。例如,在制作320-480媒体查询时,测试320px,如果它很合适,它也很适合479px。

你的断点应该是 0 - 319 320-479 480-767 768-989 990-1200 也许一些1600+和1900 +

使用这些制动点制作了不少响应式网站,它们在任何设备上都能很棒。