rem

root em,一般我们设置根元素的font-siez:62.5%,这样可以保证根元素是10px,我们设置其他属性的时候直接按比例设置即可。

vw/vh

viewport width/viewport height针对视口进行设置

媒体查询

  1. @media (min-width:1201px) {}
  2. /* 1200~800px */
  3. @media (max-width:1200px) and (min-width:800px) {}

JS控制大小和尺寸

我们可以通过控制在不同大小下的不同CSS样式

  1. ; (function (doc) {
  2. var cWidth = doc.documentElement.clientWidth;
  3. var init = function () {
  4. bindEvent();
  5. setFontSize();
  6. }
  7. function bindEvent() {
  8. window.addEventListener('resize', setFontSize, false);
  9. }
  10. function setFontSize() {
  11. var cWidth = doc.documentElement.clientWidth;
  12. if (cWidth <= 414) {
  13. doc.documentElement.style.fontSize = cWidth / 37.5 + 'px';
  14. } else {
  15. var fontSize = doc.documentElement.style.fontSize;
  16. if (fontSize !== '62.5%') {
  17. doc.documentElement.style.fontSize = '62.5%';
  18. }
  19. }
  20. }
  21. init();
  22. })(document);