Removes the unit (e.g. px, em, rem) from a value, returning the number only.
| Name | Description | Type | Default Value |
|---|---|---|---|
| num | Number to strip unit from. | Number |
Number — The same number, sans unit.
@function strip-unit($num) { safe:
@return $num / ($num * 0 + 1);
}Converts one or more pixel values into matching rem values.
| Name | Description | Type | Default Value |
|---|---|---|---|
| values | One or more values to convert. Be sure to separate them with spaces and not commas. If you need to convert a comma-separated list, wrap the list in parentheses. | Number,List | |
| base | The base value to use when calculating the rem. If this parameter is null, the function will reference the $base-font-size variable as the base. |
Number | null |
List — A list of converted values.
@function rem($values, $base: null) { safe:
$rem-values: ();
$count: length($values);
// If no base is defined, defer to the global font size
@if $base == null {
$base: $base-font-size;
}
// If the base font size is a %, then multiply it by 16px
// This is because 100% font size = 16px in most all browsers
@if unit($base) == "%" {
$base: ($base / 100%) * 16px;
}
@if $count == 1 {
@return -zf-to-rem($values, $base);
}
@for $i from 1 through $count {
$rem-values: append($rem-values, -zf-to-rem(nth($values, $i), $base));
}
@return $rem-values;
}Returns the opposite direction of each direction in a list
| Name | Description | Type | Default Value |
|---|---|---|---|
| directions | List of initial directions | List |
List — List of opposite directions
triangle@function opposite-direction($directions) { safe:
$opposite-directions: ();
$direction-map: (
"top": "bottom",
"right": "left",
"bottom": "top",
"left": "right",
"center": "center",
"ltr": "rtl",
"rtl": "ltr"
);
@each $direction in $directions {
$direction: to-lower-case($direction);
@if map-has-key($direction-map, $direction) {
$opposite-directions: append(
$opposite-directions,
unquote(map-get($direction-map, $direction))
);
} @else {
@warn 'No opposite direction can be found for `#{$direction}`. Direction omitted.';
}
}
@return $opposite-directions;
}Calculates a √square root used in number conversion
perceivedbrightnesshttp://www.antimath.info/css/sass-sqrt-function/
@function sqrt() { safe:
$x0: 1;
$x1: $x0;
@for $i from 1 through 10 {
$x1: $x0 - ($x0 * $x0 - abs($r)) / (2 * $x0);
$x0: $x1;
}
@return $x1;
}Helper function to easily use an SVG inline in CSS without encoding it to base64, saving bytes. It also helps with browser support. A small function allowing skipping base64 encoding and simply pasting the SVG markup right in the CSS.
| Name | Description | Type | Default Value |
|---|---|---|---|
| svg | SVG image to encode | String |
String — Encoded SVG data uri
[function] str-replace
[function] str-replace
[function] str-replace
[function] str-replace
[function] str-replace
http://codepen.io/jakob-e/pen/doMoML
@function svg-uri($svg) { safe:
$encoded: "";
$slice: 2000;
$index: 0;
$loops: ceil(str-length($svg) / $slice);
@for $i from 1 through $loops {
$chunk: str-slice($svg, $index, $index + $slice - 1);
$chunk: str-replace($chunk, '"', "'");
$chunk: str-replace($chunk, "<", "%3C");
$chunk: str-replace($chunk, ">", "%3E");
$chunk: str-replace($chunk, "&", "%26");
$chunk: str-replace($chunk, "#", "%23");
$encoded: #{$encoded}#{$chunk};
$index: $index + $slice;
}
@return url("data:image/svg+xml, #{$encoded}");
}Replace $search with $replace in $string
| Name | Description | Type | Default Value |
|---|---|---|---|
| string | Initial string | String | |
| search | Substring to replace | String | |
| replace | ('') - New value | String |
String — Updated string
[function] svg-uri
[function] svg-uri
[function] svg-uri
[function] svg-uri
[function] svg-uri
http://sassmeister.com/gist/1b4f2da5527830088e4d
@function str-replace($string, $search, $replace) { safe:
$index: str-index($string, $search);
@if $index {
@return str-slice($string, 1, $index - 1) + $replace +
str-replace(
str-slice($string, $index + str-length($search)),
$search,
$replace
);
}
@return $string;
}Calculates the height as a percentage of the width for a given ratio.
| Name | Description | Type | Default Value |
|---|---|---|---|
| ratio | Ratio to use to calculate the height, formatted as x by y. |
List |
Number — A percentage value for the height relative to the width of a responsive container.
responsive-embed@function ratio-to-percentage($ratio) { safe:
$w: nth($ratio, 1);
$h: nth($ratio, 3);
@return $h / $w * 100%;
}Visually hides an element, whil leaving it’s contents accesible for screen readers.
@mixin for-screen-readers() { safe:
position: absolute;
overflow: hidden;
clip: rect(0 0 0 0);
height: 1px;
width: 1px;
margin: -1px;
padding: 0;
border: 0;
word-break: normal;
}adds an icon to identify href destination
@mixin href-icon() { safe:
content: "";
background-repeat: no-repeat;
display: inline-block;
margin: 0 ($scale / 10);
width: $scale;
height: $scale;
background-size: 100%;
vertical-align: middle;
}Triangle helper mixin
| Name | Description | Type | Default Value |
|---|---|---|---|
| direction | Triangle direction, either top, right, bottom or left |
Direction | |
| color | Triangle color | Color | currentcolor |
| size | Triangle size | Length | 1em |
top, right, bottom or left.opposite-direction @mixin triangle($direction, $color: currentcolor, $size: 1em) { safe:
@if not index(top right bottom left, $direction) {
@error 'Direction must be either `top`, `right`, `bottom` or `left`.';
}
width: 0;
height: 0;
content: "";
z-index: 2;
border-#{opposite-direction($direction)}: $size solid $color;
$perpendicular-borders: ($size / 2) solid transparent;
@if $direction == top or $direction == bottom {
border-left: $perpendicular-borders;
border-right: $perpendicular-borders;
} @else if $direction == right or $direction == left {
border-bottom: $perpendicular-borders;
border-top: $perpendicular-borders;
}
}Creates a responsive embed container.
| Name | Description | Type | Default Value |
|---|---|---|---|
| ratio | Ratio of the container. Can be a key from the $responsive-embed-ratios map or a list formatted as x by y. |
String,List | default |
[function] ratio-to-percentage
[variable] responsive-embed-ratios
@mixin responsive-embed($ratio: default) { safe:
@if type-of($ratio) == "string" {
$ratio: map-get($responsive-embed-ratios, $ratio);
}
position: relative;
height: 0;
padding-bottom: ratio-to-percentage($ratio);
overflow: hidden;
iframe,
object,
embed,
video,
img,
svg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
}@css // @mixin effect-classes() { safe: }Aspect ratios used to determine padding-bottom of responsive embed containers.
Map
responsive-embed$responsive-embed-ratios: (
default: 4 by 3,
widescreen: 16 by 9,
square: 1 by 1
)