注意:
熟悉less的使用者驹碍,用Sass時(shí)請使用.scss后綴文件。
千萬別用.sass后綴文件凡恍。
.sass的劣勢:因?yàn)椴荒苁褂没ɡㄌ栔就海枰褂每s進(jìn)來進(jìn)行編輯。
.scss的優(yōu)勢:與less使用方法大致相同嚼酝。
有關(guān)移動(dòng)端$baseline-px:的設(shè)置問題:
1.iPhone5的設(shè)計(jì)圖需要改寫為:$baseline-px:64px
2.iPhone6的設(shè)計(jì)圖需要改寫為:$baseline-px:75px
3.iPhone6 plus的設(shè)計(jì)圖需要改寫為:$baseline-px:82.8px
//移動(dòng)端方案,淘寶rem轉(zhuǎn)換函數(shù)
@mixin px2rem($property, $px-values, $baseline-px:75px, $support-for-ie:false) {
//Conver the baseline into rems
$baseline-rem: $baseline-px / 1rem * 1;
//Print the first line in pixel values
@if $support-for-ie {
#{$property}: $px-values;
}
//if there is only one (numeric) value, return the property/value line for it.
@if type-of($px-values)=="number" {
#{$property}: $px-values / $baseline-rem;
}
@else {
//Create an empty list that we can dump values into
$rem-values: ();
@each $value in $px-values {
// If the value is zero or not a number, return it
@if $value==0 or type-of($value) !="number" {
$rem-values: append($rem-values, $value / $baseline-rem);
}
}
// Return the property and its list of converted values
#{$property}: $rem-values;
}
}
//移動(dòng)端方案,淘寶dpr字體轉(zhuǎn)換
@mixin font-dpr($font-size) {
font-size: $font-size;
[data-dpr="2"] & {
font-size: $font-size * 2;
}
[data-dpr="3"] & {
font-size: $font-size * 3;
}
}
例子:
Sass文件:
.selector {
// 使用px2rem進(jìn)行px計(jì)算
@include px2rem(height, 150px);
// 使用dpr進(jìn)行px計(jì)算
@include font-dpr(38px);
}
運(yùn)行結(jié)果:
.selector {
height: 2rem;
font-size: 38px;
}
[data-dpr="2"] .selector {
font-size: 76px;
}
[data-dpr="3"] .selector {
font-size: 114px;
}