<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>媒体查询案例修改背景颜色</title>
<style>
/* 1.媒体查询一般按照新从大到小或者从小到大的顺序来 */
/* 2.小于540px页面的背景颜色变为蓝色 */
@media screen and (max-width: 539px) {
body {
background-color: blue;
}
}
/* 3.540~970我们的页面颜色改为绿色 */
/* @media screen and (min-width:540px) and (max-width:969px) {
body {
background-color: green;
}
} */
/* 简化之后版本:(利用了css样式的层叠性原理) */
@media screen and (min-width:540px) {
body {
background-color: green;
}
}
/* 4.大于等于970我们页面的颜色改为红色 */
@media screen and (min-width:970px) {
body {
background-color: red;
}
}
/* 5.scree还有and必须带上不能省略的 */
/* 6.问你的数字后面必须跟单位 比如970px这个px不能省略的 */
</style>
</head>
<body>
</body>
</html>
运行效果: