媒体查询
.example {
padding: 20px;
color: white;
}
@media only screen and (max-width: 600px) {
.example {background: red;}
}
@media only screen and (min-width: 600px) {
.example {background: green;}
}
@media only screen and (min-width: 768px) {
.example {background: blue;}
}
@media only screen and (min-width: 992px) {
.example {background: orange;}
}
@media only screen and (min-width: 1200px) {
.example {background: pink;}
}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
body {
background-color:lightgreen;
}
@media screen and (max-width: 300px) {
body {
background-color:lightblue;
}
}
</style>
</head>
<body>
<p>重置浏览器查看大小。当浏览器窗口的宽度小于 300 像素时,背景颜色会变成淡蓝,否则是淡绿色。<input type="button" onclick="resize_window()" value="查看效果"></p>
<SCRIPT>
</SCRIPT>
</body>
</html>