使用rem的方法实现屏幕自适应

一,准备工作

1.下载js代码并且引入html文件之中

下载地址

https://gitee.com/lvr-ren/jbwhttps://gitee.com/lvr-ren/jbw

 

二,安装插件px2rem+,并设置基准像素数

1,安装插件

 2,设置

基准像素数:假如你的电脑为2000px,那么你的基准像素数为2000*0.1=200px

(如果你在设计一个页面,页面宽度为960,那么这时候你应该将基准像素数改为96(960*0.1=96)

我的电脑宽为1920,所以基准像素数为192.

 

3,准备好代码

 注意:你的图片,以及图片路径要改哦

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 引入代码 -->
    <meta name=" viewport "
        content=" width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no ">
    <!-- 引入js文件 -->
    <script src="./index.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>屏幕自适应</title>
    <style>
            .a1 {width: 1.041667rem/* 200/192 */;
                height: 1.041667rem/* 200/192 */;
                background-color: rgb(56, 199, 54);}
            div {width: 200px;height: 200px;
                background-color: rgb(12, 174, 228);}
            .a2 {font-size: .15625rem/* 30/192 */;}
            h1 {font-size: 30px;}
            .a3 {width: 1.041667rem/* 200/192 */}
            img {width: 200px;}
        </style>
</head>
<body>
    <div class="a1"></div>
    <div></div>
    <h1 class="a2">我会变</h1>
    <h1>我不会便</h1>
    <img src="./1 (135).png" alt="公主" class="a3">
    <img src="./1 (135).png" alt="公主">
</body>

</html>

三,结果

 

 

 

 

1

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值