CSS classes/mixins for responsive margins and padding.
npm install --save sass-spacing
HTML:
<link rel="stylesheet" href="node_modules/sass-spacing/index.css"/>
<div class="tile p:1@xs p:2@md">
<h1 class="tile__title">My Title</h1>
<p class="tile__content mt:1@xs mt:2@md">My content...</p>
</div>
- Where
m
orp
is margin or padding - Where
x
,y
,l
,r
,t
orb
is the direction in which the margin or padding is applied - Where
0
,1
,2
,3
,4
,5
,6
orauto
is the size of the margin or padding applied - Where
@*
is the breakpoint from which the margin or padding is applied
SCSS:
@import "sass-spacing/mixins.scss";
@import "sass-breakpoints/mixins.scss";
.tile {
@include p(1);
@include breakpoint('md') {
@include p(2);
}
}
.tile__content {
@include mt(1);
@include breakpoint('md') {
@include mt(2);
}
}
HTML:
<div class="tile">
<h1 class="tile__title">Tile Title</h1>
<h1 class="tile__content">Tile content...</h1>
</div>
-
m($size)
-
m($y, $x)
-
m($t, $x, $b)
-
m($t, $r, $b, $l)
-
mx($size)
-
mx($r, $l)
-
my($size)
-
my($t, $b)
-
mt($size)
-
mr($size)
-
mb($size)
-
ml($size)
Where x
, y
, l
, r
, t
or b
is the direction in which the margin is applied.
Where 0
, 1
, 2
, 3
, 4
, 5
, 6
or auto
is the $size
of the margin applied.
-
p($size)
-
p($y, $x)
-
p($t, $x, $b)
-
p($t, $r, $b, $l)
-
px($size)
-
px($r, $l)
-
py($size)
-
py($t, $b)
-
pt($size)
-
pr($size)
-
pb($size)
-
pl($size)
Where x
, y
, l
, r
, t
or b
is the direction in which the padding is applied.
Where 0
, 1
, 2
, 3
, 4
, 5
or 6
is the $size
of the padding applied.
- none - margin/padding on all sides
x
- margin/padding on the left and righty
- margin/padding on the top and bottoml
- margin/padding on the leftr
- margin/padding on the rightt
- margin/padding on the tomb
- margin/padding on the bottom
0
-0rem
margin/padding1
-.25rem
margin/padding2
-.5rem
margin/padding3
-1rem
margin/padding4
-2rem
margin/padding5
-4rem
margin/padding6
-8rem
margin/paddingauto
-auto
margin only
See the sass-breakpoints package for a list of available breakpoints.
You can customise a number of features by defining the following variables before importing sass-spacing
in your SASS file.
//specify some alternate sizing scheme
$spacing-sizes: (
'none': 0,
'xs': 4px,
'md': 16px,
'xl': 28px
);
//specify whether !important is applied
$spacing-important: false;
See the sass-breakpoints package for instructions on customising the available breakpoints.
- changed the default margin-padding sizes
- switched from attributes to class names
- removed support for ComponentJS
- added missing
m($t, $x, $b)
andp($t, $x, $b)
overrides
- added
auto
size to margin - added overrides for
m()
andp()
to set multiple properties at once
- added an option for applying
!important
to margin and padding rules and defaulted the option to true (a breaking change if you're relying on your own classes overriding the spacing mixins/classes) - changed names of the options for improved consistency and to prevent clashes with other modules (a breaking change if you're overriding the default options)
- changed the prefix from
g
tou
- theg-*
attributes are used for more utilities than just the grid (a breaking change if you're using the compiled classes) - added support for ComponentJS
The MIT License (MIT)
Copyright (c) 2015 James Newell