css常用指南,响应式网站的开发方式,简单例子

第一种,写一个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>

在这里插入图片描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值