一、媒体查询
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>媒体查询</title>
<style>
body {
background-color: pink;
color: #fff;
}
ul {
list-style-type: none;
}
ul li a {
color: green;
text-decoration: none;
padding: 3px;
display: block;
}
/*大屏幕*/
@media screen and (min-width: 1200px) {
body {
background-color: brown;
}
p{
font-size: 20px;
color: red;
}
}
/*平板电脑与小屏电脑之间的分辨率*/
@media screen and (min-width: 768px) and (max-width:979px) {
body {
background-color: blue;
}
p{
font-size: 30px;
color: black;
}
}
/*横向放置的手机和竖向放置的平板之间的分辨率*/
@media screen and (max-width:767px) {
body {
background-color: blueviolet;
}
p{
font-size: 30px;
color: red;
}
}
/*竖向放置的手机以及分别率*/
@media screen and (max-width: 480px) {
body {
background-color: black;
}
p{
font-size: 30px;
color: #fff;
}
}
</style>
</head>
<body>
<h1 >重置浏览器窗口查看效果!</h1>
<p>超大屏幕 (min-width: 1200px) 红色</p>
<p>正常屏幕 (min-width:980px)and(max-width: 1200px) 粉色</p>
<p>平板电脑与小屏电脑之间的分辨率(min-width: 768px) and (max-width:979px) 蓝色</p>
<p>横向放置的手机和竖向放置的平板之间的分辨率(max-width:767px) 紫色;</p>
<p>竖向放置的手机以及更小分别率 黑色</p>
</body>
</html>
二、引用js,用rem代替px
(function (doc, win) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function () {
var clientWidth = docEl.clientWidth;
if (clientWidth>=750) {
clientWidth = 750;
};
if (!clientWidth) return;
docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
};
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);