Base API Functions
Base has 5 functions that form the core of Base vertical grid API.
All five functions come with an unprefixed alias by default, using the base
import. Import the base-prefix
partial instead, if you only only want prefixed versions of the API.
Text functions
- Use
line-height()
,top()
andbottom()
to set text on the baseline and apply the results wherever you need them: CSSline-height
,margin
,padding
, etc. - Use
font-size()
to get the default font-size
Example
$base: (cap-height: .7);
h1 {
$font-size: 2rem;
font-size: $font-size;
line-height: line-height($font-size);
margin-top: top($font-size);
margin-bottom: bottom($font-size);
}
h1 {
font-size: 2rem;
line-height: 1.25;
margin-top: 0.05rem;
margin-bottom: 0.45rem;
}
related
@function base-font-size()
@function base-line-height()
@function base-top()
@function base-bottom()
Row function
Use row()
to set a add a specific height to a element
Examples
$base: (cap-height: .7);
.foo {
height: row(3);
}
.foo {
height: 1.5rem;
}
$base: (cap-height: .7);
h1 {
$font-size: 2rem;
font-size: $font-size;
line-height: line-height($font-size);
margin-top: top($font-size) + row(3);
margin-bottom: bottom($font-size) + row(2);
}
h1 {
font-size: 2rem;
line-height: 1.25;
margin-top: 1.55rem;
margin-bottom: 1.45rem;
}
related
@function base-row()
@function base-line-height()
aliased as line-height()
Description
Returns the line-height that is needed to maintain the text on the baseline.
The un-prefixed alias line-height()
is available by default.
Parameters & Return
$short: null (list|number)
Shorthand expression to define the current text properties, optionally containing:
- a unit number, current font-size
- a unitless number, extra rows to add per text line
$config: $base (Map)
Optional map of Base configuration settings. See $base
documentation for details.
@return (length)
Calculated line-height in a unitless number
Examples
$base: (cap-height: .5);
.foo {
line-height: line-height();
}
.foo {
line-height: 1.5;
}
$base: (cap-height: .5);
.foo {
$font-size: 2rem;
line-height: line-height($font-size);
}
.foo {
line-height: 1.25;
}
used by
@function line-height()
@function base-top()
aliased as top()
Description
Used to return the top offset needed for given font-size to maintain the baseline grid
The un-prefixed alias top()
is available by default.
Parameters & Return
$short: null (list|number)
Shorthand expression to define the current text properties, optionally containing:
- a unit number, current font-size
- a unitless number, extra rows to add per text line
static
,relative
orabsolute
for a specific math method
$config: $base (Map)
Optional map of Base configuration settings. See $base
documentation for details.
@return (length)
Calculated top shoulder
Examples
$base: (cap-height: .5);
.foo {
padding-top: top();
}
.foo {
padding-top: 0rem;
}
$base: (cap-height: .5);
.foo {
$font-size: 2rem;
padding-top: top($font-size);
}
.foo {
padding-top: 0.25rem;
}
used by
@function top()
@function base-bottom()
aliased as bottom()
Description
Used to return the bottom offset needed for given font-size to maintain the baseline grid
The un-prefixed alias bottom()
is available by default.
Parameters & Return
$short: null (list|number)
Shorthand expression to define the current text properties, optionally containing:
- a unit number, current font-size
- a unitless number, extra rows to add per text line
static
,relative
orabsolute
for a specific math method
$config: $base (Map)
Optional map of Base configuration settings. See $base
documentation for details.
@return (length)
Calculated line-height
Examples
$base: (cap-height: .5);
.foo {
padding-bottom: bottom();
}
.foo {
padding-bottom: 0rem;
}
$base: (cap-height: .5);
.foo {
$font-size: 2rem;
padding-bottom: bottom($font-size relative);
}
.foo {
padding-bottom: 0.125em;
}
requires
@function base-row()
@function _base-math-shoulder-top() [private]
@function _base-math-shoulder-bottom() [private]
used by
@function bottom()
@function base-font-size()
aliased as font-size()
Description
It returns the extracted font-size from the shorthand, if non given it will fallback on the base font-size.
The un-prefixed alias font-size()
is available by default.
Parameters & Return
$short: null (list|number)
Shorthand expression to define the current text properties, optionally containing:
- a unit number, current font-size
$config: $base (Map)
Optional map of Base configuration settings. See $base
documentation for details.
@return (length)
Raw font-size
Examples
.foo {
$font-size: 2rem;
font-size: $font-size;
}
$base: (cap-height: .5);
.foo {
font-size: font-size();
}
.foo {
font-size: 1rem;
}
$base: (cap-height: .5);
.foo {
font-size: font-size(2rem);
}
.foo {
font-size: 2rem;
}
used by
@function font-size()
@function base-row()
aliased as row()
Description
Returns the height of a certain amount of rows
Parameters & Return
$rows: 1 (Number)
Number of rows to span
$config: $base (Map)
Optional map of Base configuration settings. See $base
documentation for details.
@return (Number)
Height to span given rows
Examples
$base: (cap-height: .5);
.foo {
height: row();
}
.foo {
height: 0.5rem;
}
$base: (cap-height: .5);
.foo {
height: row(3);
}
.foo {
height: 1.5rem;
}