主页代码:
<pre name="code" class="html"><!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width"/>
<link rel="stylesheet" media="screen and (max-width: 600px), screen and (max-device-width: 600px)" href="style.css" />
<link rel="stylesheet" media="screen and (min-width: 600px), screen and (min-device-width: 600px)" href="style.css" />
</head>
<body>
</body>
</html>
css代码:
@media screen and (max-width: 600px) ,screen and (max-device-width: 600px){
body{
background-color:red;
}
}
@media screen and (min-width: 610px) ,screen and (min-device-width: 610px){
body{
background-color:yellow;
}
}
此时如果background-color:red !important;不加!important的话背景只会是黄色。
如果不加!important要实现浏览器小于600px页面是红色、大于600px页面是黄色则css文件要改成:
@media screen and (min-width: 610px) ,screen and (min-device-width: 610px){
body{
background-color:yellow;
}
}
@media screen and (max-width: 600px) ,screen and (max-device-width: 600px){
body{
background-color:red;
}
}
具体原因不清楚。