rem
root em,一般我们设置根元素的font-siez:62.5%,这样可以保证根元素是10px,我们设置其他属性的时候直接按比例设置即可。
vw/vh
viewport width/viewport height针对视口进行设置
媒体查询
@media (min-width:1201px) {}/* 1200~800px */@media (max-width:1200px) and (min-width:800px) {}
JS控制大小和尺寸
我们可以通过控制在不同大小下的不同CSS样式
; (function (doc) {var cWidth = doc.documentElement.clientWidth;var init = function () {bindEvent();setFontSize();}function bindEvent() {window.addEventListener('resize', setFontSize, false);}function setFontSize() {var cWidth = doc.documentElement.clientWidth;if (cWidth <= 414) {doc.documentElement.style.fontSize = cWidth / 37.5 + 'px';} else {var fontSize = doc.documentElement.style.fontSize;if (fontSize !== '62.5%') {doc.documentElement.style.fontSize = '62.5%';}}}init();})(document);
