Spacing
The design system uses multiples of 4px for all spacing values: dimensions, padding, and margins. The goal behind this is to achieve a consistent vertical rhythm and to reduce the cognitive load of fiddling with different spacing options.
Spacing is considered a tool for distributing content and components on a webpage. Kognifai Design System provides an easy-to-use concept, mixins and utility classes to apply and maintain spacing within and between components.
Note: These utilities are helpers, not rules. Based on context, you always have to ensure that the things you’re building look good. If that requires you to manually add unique values for margin or padding to get it “just right”, please do so. Still, try to keep custom overrides to a minimum.
We use a set of sizes to help control the use of spacing in Kognifai Design System. All sizes are defined in the file _conf_spacing.scss.
Sizes
none0px
nano2px
tiny4px
mini8px
small12px
base16px
moderate20px
medium24px
large32px
xlarge48px
xxlarge64px
xxxlarge128px
Use spacing in HTML
As with grid-classes, you can apply classes for spacing into your HTML. Spacing-classes use a similar syntax when it comes to responsive design as grids, namely using the @-symbol for scoping when a spacing-class should have effect. As with grids, the scoping conditions for spacing follow the same global breakpoints definition.
Here is an example snippet. Notice the classes used on the kx-col-element.
<link rel="stylesheet" href="path-to-designsystem-css"/>
<div class="kx-p--base kx-p--xlarge@tab-m kx-p--xxxlarge@ltp-m">
<h2>Responsive padding!</h2>
<p>Try resizing your browsers</p>
</div>
Here is how it looks. Try resizing your browser to se the padding change.
Responsive padding!
Try resizing your browsers
- Where
kx-morkx-pis margin or padding. - Where
x,y,l,r,torbis the direction in which the margin or padding is applied. Like this:kx-py,kx-mx,kx-pbetc. - Where
none,nano,tiny,mini,small,base,moderate,mediumlarge,large,xlarge,xxlarge,xxxlarge, orautois the$sizeof the margin or padding applied. - Where
@is the breakpoint from which the margin or padding is applied. autois, in most situations, only supported forml,mrormx. W3C spec says it like this: “If “margin-top” or “margin-bottom” is “auto”, their used value is 0″. But if used together with flexbox utilities likekx-flex-columnandkx-align-items, they do actually work. Read more about Flexobox utilities.
Use spacing in Scss
If you use Scss, we provide simple mixins that can be used directly in your stylesheet. Let’s use the same example from above:
@import 'path-to/conf_mq'; // Definition for media queries
@import 'path-to/conf_spacing'; // Definition for spacing
@import 'path-to/mq'; // Mixins for Media Queries
@import 'path-to/mix_spacing'; // Mixins for Media Queries
.foo {
@include p(base);
@include mq($from: tab-m) {
@include p(xlarge);
}
}
The example above compiles to the following css:
.foo {
padding: 1rem; /* = 16px*/
}
@media all and (min-width: 48.0625rem) {
.foo {
padding: 3rem; /* = 48px*/
}
}
This snippet sets a default value for padding on a component called .foo. If viewport size is larger than “a medium tablet” (tab-m = 769px = 48.0625rem), the padding increases from 16px to 48px in all directions. Quite simple!
Margin
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)
Padding
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)
Directions
- 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 bottomauto- margin auto either left, right or both