selfcreditgiving
V2EX  ›  问与答

页面自适应有的只能用 px 做为宽高,大家是怎么做的?

  •  
  •   selfcreditgiving · Sep 22, 2019 · 1771 views
    This topic created in 2428 days ago, the information mentioned may be changed or developed.

    页面自适应 我是把设计稿的 px 转成 vw 来实现页面自适应的。

    // 使用 vw 转化成和设计稿一样的尺寸
    $ui-width: 960px;
    @function px2vw($px) {
      @return $px / $ui-width * 100vw;
    }
    

    然后就把设计稿的 px 尺寸 填到这个函数里就可以了:

    .box {
      heigth: px2vw(100px);
    }
    

    但是有的地方是只允许 px 或者 宽高百分比 这样的单位,

    比如说 echarts 里的 option、element-ui 里面组件的属性 这些。

    这些要做自适应一般是怎么实现的呢?

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3057 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 06:21 · PVG 14:21 · LAX 23:21 · JFK 02:21
    ♥ Do have faith in what you're doing.