css中的@media媒体查询用法总结

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title></title>
		<style>
			*{
				margin: 0;padding: 0;
			}
		    .container{
		        width:100vw;
		        margin: 0 auto;
		        height:100vh;
				max-height: 100vh;
		        background-color: red;
	/* 			background: url(img/bgc.jpg) center center / cover no-repeat rgb(34, 34, 34);
				overflow: hidden; */
		    }
			.container::before{
				content: "大于1200px";
			}
		    /*媒体查询:注意and后面需要留空格*/
			@media screen and (max-width: 414px) {
			    .container{
			        width:100%;
			        background-color: green;
			    }
				.container::before{
					content: "414-768px";
					font-size: 30px;
					color: #55ff00;
					text-align: center;
					display: flex;
					justify-content: center;
				}
			}
		    /*iphone768以下: w < 768px*/
		    @media screen and (max-width: 768px) and (min-width: 414px) {
		        .container{
		            width:100%;
					height: 50vh;
		            background-color: green;
		        }
				.container::before{
					content: "414-768px";
					font-size: 30px;
					color: #ff0000;
					text-align: center;
					display: flex;
					justify-content: center;
				}
		    }
		    /*iPad: w >= 768  && w< 992*/
		    @media screen and (max-width: 992px) and (min-width: 768px) {
		        .container{
		            width:750px;
		            background-color: blue;
					height: 70vh;
		        }
				.container::before{
					content: "768px-992px";
					font-size: 30px;
					color: #FFFFFF;
					text-align: center;
					display: flex;
					justify-content: center;
					
				}
		    }
		    /*中等屏幕   w >= 992  && w<1200*/
		    @media screen and (max-width: 1200px) and (min-width: 992px) {
		        .container{
		            width:970px;
		            background-color: pink;
					height: 80vh;
		        }
				.container::before{
					content: "992px-1200px";
					font-size: 30px;
					color: #000000;
					text-align: center;
					display: flex;
					justify-content: center;
				}
		    }
		</style>
	</head>
	<body>
		<div class="container">
			<div>asdd</div>
			<div>ss</div>
			
		</div>
	</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值