CSS
@media 媒体查询
当媒体查询被触发时,执行媒体查询内的语块。
例子:当浏览器窗口长度改变时,改变方块颜色。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
.one{
width: 800px;
height: 400px;
background-color: black;
margin: 20px;
float: left;
}
.two{
font-size: 60px;
margin: 0px;
text-align: center;
line-height: 400px;
}
.two::after{
content: "";
display: block;
clear: both;
}
@media (min-width:1280px) and (max-width:1440px) {
.one{
width: 700px;
height: 350px;
margin: 15px;
background-color: green;
}
.two{
font-size: 50px;
line-height: 350px;
}
}
@media (min-width:1024px) and (max-width:1280px) {
.one{
width: 600px;
height: 300px;
margin: 15px;
background-color: blue;
}
.two{
font-size: 40px;
line-height: 300px;
}
}
@media (min-width:769px) and (max-width:1024px) {
.one{
width: 500px;
height: 250px;
margin: 10px;
background-color: yellow;
}
.two{
font-size: 30px;
line-height: 250px;
}
}
@media (min-width:640px) and (max-width:768px) {
.one{
width: 400px;
height: 200px;
margin: 10px;
background-color: red;
}
.two{
font-size: 25px;
line-height: 200px;
}
}
@media (min-width:375px) and (max-width:640px) {
.one{
width: 100%;
height: 200px;
margin: 10px;
background-color: pink;
}
.two{
font-size: 40px;
line-height: 80px;
}
}
@media (max-width:375px) {
.one{
width: 100%;
height: 150px;
margin: 0px;
background-color: orange;
}
.two{
font-size:20px;
line-height: 40px;
}
}
</style>
</head>
<body>
<div class="one">
</div>
<p class="two">
Hello World
</p>
<div class="one">
</div>
<p class = "two">
Hello World
</p>
</body>
</html>