media媒体查询

1、根据不同的浏览设备加载不同的css

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<link media="screen" rel="stylesheet" href="css/screen.css">
	<link media="print" rel="stylesheet" href="css/print.css">
</head>
<body>
	<h1>hello world</h1>
	<div class="box">
		<h1>根据不同的浏览设备加载不同的css</h1>
		<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolorem omnis in autem, et non explicabo nisi necessitatibus iusto possimus aspernatur totam laboriosam quis velit sunt atque ducimus maxime quia reprehenderit.</p>
	</div>
</body>
</html>
screen.css

body{
	font-size: 12px;
}
.box{
	font-size: 14px;
	color: #FFF;
	background: green;
}
print.css

body{
	font-size: 12px;
}
.box{
	font-size: 19px;
	color: #FFF;
	background: red;
}
效果:

(1)浏览器界面下:



(2)打印机下:

------------------------------------------------------------------------

2、根据屏幕尺寸不同,加载不同CSS文件

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<link media="screen and (min-width:992px)" rel="stylesheet" href="css/screen_pc.css">
	<link media="screen and (min-width:768px) and (max-width:991px)" rel="stylesheet" href="css/screen_pad.css">
	<link media="screen and (max-width:767px)" rel="stylesheet" href="css/screen_phone.css">
</head>
<body>
	<h1>hello world</h1>
	<div class="box">
		<h1>根据屏幕尺寸不同,加载不同CSS文件</h1>
		<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolorem omnis in autem, et non explicabo nisi necessitatibus iusto possimus aspernatur totam laboriosam quis velit sunt atque ducimus maxime quia reprehenderit.</p>
	</div>
</body>
</html>
screen_pc.css:

.box{
	font-size: 23px;
	color: pink;
	background: green;
}
screen_pad.css:

.box{
	font-size: 16px;
	color: #FFF;
	background: #000;
}
screen_phone.css:

.box{
	font-size: 12px;
	color: orange;
	background: #FFF;
}
-------------------------------------------------------------

3、根据屏幕尺寸不同,加载不同CSS片段

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<link rel="stylesheet" href="css/screens.css">
</head>
<body>
	<h1>hello world</h1>
	<div class="box">
		<h1>根据屏幕尺寸不同,加载不同CSS片段</h1>
		<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolorem omnis in autem, et non explicabo nisi necessitatibus iusto possimus aspernatur totam laboriosam quis velit sunt atque ducimus maxime quia reprehenderit.</p>
	</div>
</body>
</html>

screens.css

/* pc */
@media screen and (min-width: 992px){
	.box{
		font-size: 23px;
		color: pink;
		background: green;
	}
	h1{font-size: 2em}
}
/* pad */
@media screen and (min-width: 768px) and (max-width: 991px){
	.box{
		font-size: 16px;
		color: #FFF;
		background: #000;
	}
	h1{font-size: 1em}
}
/* phone */
@media screen and (max-width: 767px){
	.box{
		font-size: 12px;
		color: orange;
		background: #FFF;
	}
	h1{font-size: 0.5em}
}







  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值