【pc与移动端适配小tip】使用scss做vh,vw单位适配,scss的mixin与function方法


UI给的设计图尺寸:
pc:1920
980
H5:375*767
适配尺寸根据自己需求而定

mixin方法 (给具体的属性配置)

宽度适配

@mixin module-width($argus, $mentods){
  @if($mentods == 'pc'){
    width: ($argus / 1920) * 100vw;
  } @else if($mentods == 'H5'){
    width: ($argus / 375) * 100vw !important;
  }
}

使用:

div{
	//pc端
	@include module-width(100, 'pc');
	//H5端
	@include module-width(100, 'H5');
}

高度适配

@mixin module-height($argus, $mentods){
  @if($mentods == 'pc'){
    height: ($argus / 980) * 100vh;
  } @else if($mentods == 'H5'){
    height: ($argus / 767) * 100vh !important;
  }
}

使用:

div{
	//pc端
	@include module-height(100, 'pc');
	//H5端
	@include module-height(100, 'H5');
}

字体大小适配

(这里我的字体是用的vh做单位)

@mixin font-size($argus, $mentods){
  @if($mentods == 'pc'){
    font-size: ($argus / 980) * 100vh;
  } @else if($mentods == 'H5'){
    font-size: ($argus / 767) * 100vh !important;
  }
}

使用:

div{
	//pc端
	@include font-size(20, 'pc');
	//H5端
	@include font-size(20, 'H5');
}

function方法(仅配置属性参数)

横向参数适配

@function adaptation-width($argus, $mentods){
  @if($mentods == 'pc'){
    @return ($argus / 1920) * 100;
  } @else if($mentods == 'H5'){
    @return ($argus / 375) * 100;
  }
}

竖向参数适配

@function adaptation-height($argus, $mentods){
  @if($mentods == 'pc'){
    @return ($argus / 980) * 100;
  } @else if($mentods == 'H5'){
    @return ($argus / 767) * 100;
  }
}

使用:

div{
	width: adaptation-width(50vw, 'pc');
	height: adaptation-height(50vh, 'pc');
	padding: adaptation-height(5vh, 'pc') adaptation-width(5vw, 'pc');
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值