html适应各个手机端页面的js

1.首先定义一个换算函数

function getRem(pwidth, prem) {
    var html = document.getElementsByTagName("html")[0];
    var oWidth = document.body.clientWidth || document.documentElement.clientWidth;
    html.style.fontSize = oWidth / pwidth * prem + "px";
}

2.页面加载之前调用函数,并定义换算单位(我定义的是100)

window.ready(function () {
    getRem(750, 100);
});

3.开始写css

列如一个class为one的盒子长2327px,宽750px

<div class="one"></div>

可以这样写

.one {
    height: 23.27rem;
    width:7.5rem;
}

猜你喜欢

转载自blog.csdn.net/hsdiana/article/details/81169081
今日推荐