vue-cli3实现屏幕自适应(两步搞定)

项目演示代码

<template>
    <div class="big">
        <div class="box1"></div>
        <div class="box2"></div>
        <div class="box3" style="width:1920px;background: skyblue;"></div>
    </div>
</template>

<script>

    export default {
        name: 'test',
        components: {}
    }
</script>
<style>
    * {
        margin: 0;
        padding: 0;
    }
</style>
<style scoped>
    .big {
        width: 100vw;
        height: 100vh;
        background: yellowgreen;
    }

    .big div {
        height: 100px;
    }

    .big img {
        width: 710px;
        height: 400px;
    }

    .box1 {
        width: 960px;
        background: tomato;
    }

    .box2 {
        width: 1920px;
        background-color: darkred;
    }
</style>

第一步:安装postcss-px-to-viewport

npm install --save postcss-px-to-viewport

第二步:启动项目(重启)

npm run serve

效果展示

  1. 标准分辨率(1920 * 1200)
    #
  2. 默认分辨率(1440 * 900)在这里插入图片描述
    3.其他分辨率(1024 * 640)
    在这里插入图片描述
  • 参考资料
    • vue-cli2自适应参考:https://www.jianshu.com/p/a7c4ff4ed14c
    • cli3:https://www.cnblogs.com/liuXiaoDi/p/13188052.html
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值