第一种,写一个css文件
.zong{
width: 100%;
border: 1px solid rebeccapurple;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
/* 超小屏幕 */
@media only screen and (max-width:767px){
.zong div{
width: 100%;
background-color: blue;
}
}
/* 小屏幕 */
@media only screen and (min-width:768px) and (max-width:992px){
.zong div{
width: 50%;
background-color: green;
}
}
/*大屏幕*/
@media only screen and (min-width:993px) and (max-width:1200px){
.zong div{
width: 33%;
background-color: pink;
}
}
/*大屏幕*/
@media only screen and (min-width:1201px){
.zong div{
width: 25%;
background-color: darkorange;
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="css/index.css"/>
</head>
<body>
<div class="zong">
<div>
商品
</div>
<div>
商品
</div>
<div>
商品
</div>
<div>
商品
</div>
</div>
</body>
</html>
第二种,写多个css文件,在html引用时做判断
common
.zong{
width: 100%;
border: 1px solid rebeccapurple;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
iphone
.zong div{
width: 100%;
background-color: blue;
}
ipad
.zong div{
width: 50%;
background-color: green;
}
pc
.zong div{
width: 33%;
background-color: pink;
}
big_pc
.zong div{
width: 25%;
background-color: darkorange;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="css/common.css"/>
<link rel="stylesheet" media="screen and (max-width:767px)" href="css/iphone.css"/>
<link rel="stylesheet" media="screen and (min-width:768px) and (max-width:992px)" href="css/ipad.css"/>
<link rel="stylesheet" media="screen and (min-width:993px) and (max-width:1200px)" href="css/pc.css"/>
<link rel="stylesheet" media="screen and (min-width:1201px)" href="css/big_pc.css"/>
</head>
<body>
<div class="zong">
<div>
商品
</div>
<div>
商品
</div>
<div>
商品
</div>
<div>
商品
</div>
</div>
</body>
</html>