我的媒体查询在我的桌面上按预期工作,但在手机或平板电脑上却没有。请在此处查看实时代码http://jsfiddle.net/E8cgT/
如果屏幕大于 1024 像素,它应该是绿色的,我的平板电脑屏幕是绿色的,但背景保持黄色。
这也发生在我的手机上,不管什么是黄色的。
或阅读下文
我的html:
<html>
<head>
<title>Home Page</title>
<link rel="stylesheet" media="all" type="text/css" href="style.css"/>
</head>
<body>
<div id="master">
<header>
</header>
<nav>
Welcome to the home page from the sites directory
<ul>
<li><a href="#">Meet Your Sensei</a></li>
<li><a href="#">Tour Our Dojo</a></li>
<li><a href="#">Our Martial Art Program</a></li>
<li><a href="#">Our Training Schedule</a></li>
<li><a href="#">Current Events</a></li>
<li><a href="#">FAQ</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</div><!-- end of the master div tag -->
</body>
</html>
我的CSS:
/* this will not work as we have below media to over ride */
body{ background-color: red;}
/* Low resolution for cell phones for 480 and below
*/
@media only screen and (max-width:480px)
{body{background-color: blue;}}
/* High resolution for screen between 1024 and above
*/
@media only screen and (min-width:1024px)
{body{background-color: green;}}
/* Medium resolution for screen between 481 and above
*/
@media only screen and (min-width:481px)
{body{background-color: yellow;}}
[解决方案]
1)视口是我不知道的东西。
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2)我改变了屏幕的优先级毕竟是套管样式表。
body {
background-color: red;
}
@media screen and (max-width:480px)
{body{background-color: blue;}}
/* Medium resolution for screen between 481 and above
*/
@media screen and (min-width:481px)
{body{background-color: yellow;}}
/* High resolution for screen between 1024 and above
*/
@media screen and (min-width:1024px)
{body{background-color: green;}}
谢谢你们。