设为首页 加入收藏

TOP

rem
2019-10-09 20:03:48 】 浏览:59
Tags:rem

通过sass动态设置rem

移动端我们一般是根据iPhone6的375来进行开发的

ex:

js文件:

let htmlWidth = document.documentElement.clientWidth || document.body.cilentWidth;
// 获取视窗高度
let htmlDom = document.getElementsByTagName('html')[0];
htmlDom.style.fontSize = htmlWidth / 10 + 'px';
// console.log(htmlWidth,htmlWidth / 10);
//动态修改font-size
window.addEventListener('resize',()=>{
  let htmlWidth = document.documentElement.clientWidth || document.body.cilentWidth;
  let htmlDom = document.getElementsByTagName('html')[0];
  htmlDom.style.fontSize = htmlWidth / 10 + 'px';
})

在vscode中编写sass文件:

@function px2rem($px) {
  $rem:37.5px;/* 基准值iphon6 375/10 */
  @return ($px / $rem) +rem;
}
/* 以iPhone6 为主 设计给的尺寸要比实际大两倍 */
html{
  background: #f8f8f8;
}
.header{
  width: 100%;
  height: px2rem(40px);
  background: red;
  .header-content{
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: px2rem(40px);
    padding: 0 px2rem(23px);
    .header-item{
      color:#ffcdce;
      font-size: px2rem(16px);
      &:nth-child(2){//&:等同于父元素
        color: #fff;
        font-size: px2rem(17px);
      }
    }
  }
}

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇前端基础笔记(一) 下一篇【Vue.js实战案例】- Vue.js实现..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目