A collection of Sass functions & mixins.
npm install --save sass-kit
As these are functions and mixins they can all be imported and will only impact the size of the compiled CSS if used:
@import 'node_modules/sass-kit/index';
h1 { font-size: em( 24px ); }
Optionally, the utility CSS classes can be imported as well.
This will add to the size of the compiled CSS regardless of if they are used:
@import 'node_modules/sass-kit/index';
@import 'node_modules/sass-kit/util-classes';
<div class="u-cf">...</div>
<div class="u-visually-hidden">...</div>
See the source and tests for examples.
String replacement
Remove units from a value
Get the lower bound of an array
Get the upper bound of an array
Convert a pixel value to ems
Convert a pixel value to rems
Generate an image asset URL based on $asset-base-path
Generate an font asset URL based on $asset-base-path
Get a value from the color palette
Convert Photoshop "tracking" to CSS letter spacing
Calculate correct nested border radii sizes
Output dimensions as rem
with px
fallbacks
Cross browser inline block
Cross browser opacity
Image replacement #1
Image replacement #2
Clearfix
hidden
Hide from both screenreaders and browsers
visually-hidden( $focusable: ?bool )
Hide only visually, but have it available for screenreaders
Hide visually and from screenreaders, but maintain layout
Text overflow ellipsis
Hyphenate long words
iOS smooth momentum scrolling
Text antialiasing
Adjust font rendering of light text on dark backgrounds in Chrome on macOS
Prevent an element from being clickable and allow the click to pass through to the element below
Cover an element
Generates a fallback for alpha colors based on the background & foreground colors
Generate all the necessary font-face properties
Vertical centering for legacy browsers
Easy vertical centering of anything in IE9+
Easy horizontal & vertical centering of anything in IE9+
Center block level content
Responsive background images that maintain their aspect ratio
Media object pattern
Makes media embeds maintain a fixed aspect ratio but adapt to the width of their parent container
Responsive / media query helpers.
An em
Sass function is required to convert px
values to ems
. You can provide one or import the included functions/em
file as well:
@import 'node_modules/sass-kit/functions/em';
@import 'node_modules/sass-kit/mixins/responsive';
p {
color: black;
@include below( 320px ) {
color: red;
}
@include between( 480px, 500px ) {
color: cyan;
}
@include above( 720px ) {
color: orange;
}
@include landscape() {
color: green;
}
@include portrait() {
color: blue;
}
}
Don't convert the media queries to ems:
@import 'node_modules/sass-kit/mixins/responsive';
p {
color: black;
@include below( 320px, $convert: false ) {
color: red;
}
@include between( 480px, 500px, $convert: false ) {
color: cyan;
}
@include above( 720px, $convert: false ) {
color: blue;
}
}
@import 'node_modules/sass-kit/functions/em';
@import 'node_modules/sass-kit/mixins/responsive';
p {
@include above( 720px, height ) {
color: cyan;
}
}
You can also use predefined keywords, to do so create a map called $breakpoints
:
@import 'node_modules/sass-kit/functions/em';
@import 'node_modules/sass-kit/mixins/responsive';
// these are the predefined keywords which you can overwrite
$breakpoints: (
small : 320px,
medium : 640px,
large : 1024px,
xlarge : 1440px,
xxlarge: 1920px,
);
p {
@include above( medium ) {
color: cyan;
}
}
The following mixins are available:
The base mixin.
$type
Breakpoint type, one of 'above'
, 'below'
, 'between'
.
$from
Breakpoint start.
$to
Default: false
Breakpoint end, only required for $type: 'between'
.
$dimension
Default: 'width'
Breakpoint dimension, one of 'width'
, 'height'
.
$convert
Default: true
Convert px based $from
& $to
values to ems
.
Include styles below $size
.
Include styles above $size
.
Include styles between $from
& $to
.
Include styles in landscape orientation.
Include styles in portrait orientation.