PC端与移动端的重置样式 reset.css 与 单位转换 remscale.js

本文探讨了如何通过remscale.js实现从设计稿750px到移动端适配的技巧,涉及PC端与移动端CSS样式调整,并介绍px到rem的转换方法,以及如何利用VSCode插件pxtorem提高开发效率。
摘要由CSDN通过智能技术生成

PC端的

html,body{-webkit-text-size-adjust: 100%;}
body{
    margin:0;
    font:12px/1 "微软雅黑","宋体";
}
h1,h2,h3,h4,h5,h6{
    margin:0;
    /* 与父元素字号一致 */
    font-size: 100%;
    font-weight: normal;
}
p,dl,dd{
    margin:0;
}
ul,ol{
    /* 清除列表样式 */
    list-style: none;
    margin:0;
    padding:0;
}
strong,b{
    font-weight: normal;
}
em,i{
    font-style: normal;
}
a{
    color:#666666;
}
a,del{
    text-decoration: none;
}
input{
    padding:0;
    margin:0;
    border:none;
    background:none;
}
a,input,textarea,select{
    -webkit-tap-highlight-color: rgba(0,0,0,0);
}
input,textarea{
    -webkit-appearance: none; 
    border-radius: 0;
}
img{
    /* 去除下间隙 */
    vertical-align: middle;
    /* 清除ie图片超链接 的蓝色边框*/
    border-style:none;
}
table{
    /* 边框合并 */
    border-collapse: collapse;
}
td,th{
    padding:0;
}
/* 清浮动 */
.clearfix:after,.layout:after{
    content:"";
    display: block;
    clear: both;

    /* 避免产生间隙问题 */
    font-size:0;
    line-height:0;
    overflow: hidden;
    height:0;
}

移动端的

html,body{-webkit-text-size-adjust: 100%;}
body{
    margin:0;
    font:12px/1.12 "微软雅黑";
}
h1,h2,h3,h4,h5,h6{margin:0;
    /* 与父元素字号一致 */
    font-size: 100%;
    font-weight: normal;
}
p,dl,dd{
    margin:0;
}
ul,ol{
    /* 清除列表样式 */
    list-style: none;
    margin:0;
    padding:0;

}
strong,b{
    font-weight: normal;
}
em,i{
    font-style: normal;
}
a{
    color:#666666;
}
a,del{
    text-decoration: none;
}
input{
    padding:0;
    margin:0;
    border:none;
    background:none;
}
a,input,textarea,select{
    -webkit-tap-highlight-color: rgba(0,0,0,0);
}
input,textarea{
    -webkit-appearance: none; 
    border-radius: 0;
}
img{
    /* 去除下间隙 */
    vertical-align: middle;
    /* 清除ie图片超链接 的蓝色边框*/
    border-style:none;
}
table{
    /* 边框合并 */
    border-collapse: collapse;
}
td,th{
    padding:0;
}
/* 清浮动 */
.clearfix:after,.layout:after{
    content:"";
    display: block;
    clear: both;

    /* 避免产生间隙问题 */
    font-size:0;
    line-height:0;
    overflow: hidden;
    height:0;
}

移动端转换单位px到rem的 remscale.js
我这里默认设计稿的宽度为750px;

(function (doc, win) {
    var docEl = doc.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function () {			
            
            var clientWidth = docEl.clientWidth; //获取设备尺寸       
            console.log(clientWidth);
            if (!clientWidth) return;
            if(clientWidth>=750){ //设计稿宽度
                 docEl.style.fontSize = '100px';
            }else{
                docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
            }
        };
    if (!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false); //绑定事件
    doc.addEventListener('DOMContentLoaded', recalc, false);
    
})(document, window);


编写代码时候如果用的是vscode可以使用插件:px to rem

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值