Skip to content

Instantly share code, notes, and snippets.

@Hokid
Created January 11, 2015 14:35
(sass) конвертор в em
// ----
// Sass (v3.4.9)
// Compass (v1.0.1)
// ----
@function em( $input:null, $em:16 ) {
$support-num: px em;
$support-str: auto;
$output: ();
@if not $input { @error "#{$input}"; @return null }
@if not unitless( $em ) {
$em-unit: unit( $em );
@if $em-unit == px { $em: $em/1px }
@else if $em-unit == em { $em: $em/1em*16 }
@else { @error "#{$em}."; @return null }
}
@each $i in $input {
$i-type: type-of( $i );
@if $i-type == number {
$i-unit: unit( $i );
$i-unitless: unitless( $i );
@if not $i-unitless and not index( $support-num, $i-unit ) { @error "( #{$i} )"; @return null }
@else if $i == 0 { $i: 0 }
@else if $i-unitless { $i: $i*1em/$em }
@else if $i-unit == px { $i: $i/1px*1em/$em }
}
@else if $i-type == string {
@if not index( $support-str, $i ) { @error "( #{$i} )"; @return null }
}
$output: append( $output, $i )
}
@if length( $output ) == 1 { @return nth( $output, 1 ) }
@return $output;
}
.a{
test: em( 2px 3 4em auto, 20px);
}
.a {
test: 0.1em 0.15em 4em auto;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment