-
Notifications
You must be signed in to change notification settings - Fork 5
/
_em.scss
36 lines (30 loc) · 952 Bytes
/
_em.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/// Converts a target value in pixels to its associated value in ems based on a context.
/// @param {Integer | Pixels | List} $target - The target size in either pixels or its integer equivalent.
/// @param {Map} $context [$baseFontSize] - The context size in either pixels or its integer equivalent.
/// @return {Number} The target's value in ems within the given context.
/// @example
/// em(12)
/// // 0.75em
/// @example
/// em(12 16, (context: 24))
/// // 0.5em 0.6666em
@function em($target, $options: ()) {
$options: map-merge((
context: $baseFontSize
), $options);
$output: null;
$context: map-get($options, context);
@if type-of($target) == list {
$output: unquote('') !default;
@each $value in $target {
$value: em($value, (context: $context));
$output: append($output, $value);
}
}
@else {
$target: parseInt($target);
$context: parseInt($context);
$output: ($target / $context) * 1em;
}
@return $output;
}