
Security News
Official Go SDK for MCP in Development, Stable Release Expected in August
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.
postcss-tidy-columns
Advanced tools
PostCSS plugin to manage column alignment.
PostCSS Tidy Columns sets an element's width and margins independent of the
width of its parent, allowing for easy vertical alignment of elements. It does
this by calculating the width based on vw
units and sets the max-width
using
static values based on the site's maximum width.
PostCSS Tidy Columns does not set layout. Positioning elements is your job.
npm install postcss-tidy-columns
/* Input example */
@tidy columns 12;
@tidy gap 1.25rem;
@tidy edge 2rem;
@tidy site-max 90rem;
div {
tidy-span: 3;
tidy-offset: 2;
}
/* Output example */
div {
width: calc((((100vw - 2rem * 2) / 12 - 1.1458rem) * 3) + 1.25rem * 2);
max-width: calc((((90rem - 2rem * 2) / 12 - 1.1458rem) * 3) + 1.25rem * 2);
margin-left: calc((((100vw - 2rem * 2) / 12 - 1.1458rem) * 2) + 1.25rem * 2);
}
@media (min-width: 90rem) {
div {
margin-left: calc((((90rem - 2rem * 2) / 12 - 1.1458rem) * 2) + 1.25rem * 2);
}
}
postcss([ require('postcss-tidy-columns') ])
See PostCSS docs for examples for your environment.
The tidy-span
property specifies the number of columns and adjacent column
gaps (if any) the element should span.
Syntax
tidy-span: 4;
Values
<number>
The number of columns the element should span.
The tidy-offset-left
property specifies the number of columns and adjacent
column gaps the element's left margin should span.
Offsets use a siteMax
breakpoint, since there's no max-margin
CSS property.
Syntax
tidy-offset-left: 2;
Values
<number>
The number of columns the element should be offset from the left edge of the parent element.
The tidy-offset-right
property specifies the number of columns and adjacent
column gaps the element's right margin should span.
Offsets use a siteMax
breakpoint, since there's no max-margin
CSS property.
Syntax
tidy-offset-right: 1;
Values
<number>
The number of columns the element should be offset from the right edge of the parent element.
tidy-column
is a shorthand property for setting tidy-offset-left
,
tidy-span
, and tidy-offset-right
in one declaration.
Syntax
tidy-column: 3 / span 2 / 4; tidy-column: 0 / span 4 / 1; /* could also use `inherit` in place of `0` */ tidy-column: 1 / span 4;
Values
[ <number> | 'inherit' ]
The left offset value.
span <number>
The column span value.
[ <number> | 'inherit' ]
(optional)
The right offset value.
Formal syntax
[ <number> | 'inherit' ] / span && <number> [ / <number> ]?
tidy-offset
is a shorthand property for setting tidy-offset-left
and
tidy-offset-right
in one declaration.
Syntax
tidy-offset: 3 / 4; tidy-offset: 0 / 1; /* could also use `inherit` in place of `0` */ tidy-offset: 1;
Values
[ <number> | 'inherit' ]
The left offset value.
/ <number>
(optional)
The right offset value.
Formal syntax
[ <number> | 'inherit' ] [ / <number> ]?
The inherit
value simply acts as a way to bypass the need to enter a required
value in the shorthand properties. Nothing is actually inherited, but I found
using a 0
value, which does the same thing, could potentially be confusing.
These functions are provided for incorporating the tidy-span
and
tidy-offset
output without using those properties. These can be used on their
own or nested inside a calc()
function.
When using these functions, the siteMax
media query will not be added. Use
the tidy-span-full()
and tidy-offset-full()
functions to set the static
column and offset widths, respectively.
Use cases include:
offset
value on properties other than margin
; for example, on an
absolutely-positioned element.span
value properties other than width
and max-width
, such as in
a translate
function.span
or offset
of an element by an arbitrary amount, because
sometimes designers just do what they want...tidy-span()
and tidy-span-full()
functions return the span
property's
calc()
declaration for use in assigning widths.
Syntax
/* property: tidy-span(number) */ /* property: calc(tidy-span(number) expression) */ div { width: calc(tidy-span(3) + 4rem); } @media (min-width: 75rem) { div { width: calc(tidy-span-full(3) + 4rem); } }
Formal syntax
tidy-span( <number> )
tidy-span-full( <number> )
calc( tidy-span( <number> ) <calc-sum>)
calc( tidy-span-full( <number> ) <calc-sum>)
See MDN for more about the CSS calc() function.
tidy-offset()
and tidy-offset-full()
functions return the offset
property's calc()
declaration for use in positioning.
Syntax
/* property: tidy-offset(number) */ /* property: calc(tidy-offset(number) expression) */ div { left: calc(tidy-offset(1) + 2rem); } @media (min-width: 75rem) { div { left: calc(tidy-offset-full(1) + 2rem); } }
Formal syntax
tidy-offset( <number> )
tidy-offset-full( <number> )
calc( tidy-offset( <number> ) <calc-sum>)
calc( tidy-offset-full( <number> ) <calc-sum>)
See MDN for more about the CSS calc() function.
Name | Type | Default | Description |
---|---|---|---|
columns | {Number} | 12 | The number of columns in your grid. |
gap | {String} | undefined | The width of column gaps. |
siteMax | {String} | undefined | The max-width of the site. |
edge | {String} | undefined | The value of the site's edge padding. |
addGap | {Boolean} | false | Add a right gap margin to column declarations. |
columns
Declares the number of columns in your design. Supports any positive integer.
CSS Syntax
@tidy columns <number>;
gap
Declares the width of the gap between each column. Supports any positive integer
of unit [px
|em
|rem
].
CSS Syntax
@tidy gap <length>;
Formal syntax
<length> [ / <boolean> ]?
See
addGap
for more about this syntax.
siteMax
Declares the max-width of the site, at which point the site transitions from
fluid width to static width. Setting a siteMax
value ensures the column and
margin widths are correct once the site no longer spans the full viewport width.
Supports any positive integer of unit [px
|em
|rem
].
CSS Syntax
@tidy site-max <length>; /* Alternatively use the camelCased JavaScript property */ @tidy siteMax <length>;
edge
Set edge
to the value of the space between the content and the edge of the page.
Supports any positive integer of unit [px
|em
|rem
].
CSS Syntax
@tidy edge <length>;
addGap
Declares whether or not to add a right gap margin to the column.
When this is set to true
, a :last-of-type
rule will be added to reset the
margin-right
to 0
for the last item.
CSS Syntax
/* Declared as a boolean value after `gap`; must be preceeded by a slash */ @tidy gap <length> / <boolean>;
Formal syntax
<length> [ / <boolean> ]?
As an alternative to the PostCSS JavaScript API, options may also be passed via stylesheet at-rules. See the above options for the CSS syntax.
Global options are defined via @tidy
rules outside of any selector
blocks. Values declared here take precedence over the options passed
to Tidy Columns via JavaScript.
Local options are defined via @tidy
rules inside a selector block
and are scoped to the parent selector. Values declared here take precedence over
the global options.
CSS Custom Proprties are
supported in @tidy
rules, with the following caveats:
@tidy site-max
value will throw an error.@tidy gap
custom property value must only contain its length and not its
/ <boolean>
portion of the gap shorthand.Example:
:root {
--columns: 16;
--gap: 0.625rem;
--edge: 1.25;
}
@media (min-width: 75rem) {
:root {
--gap: 1rem;
--edge: 2rem;
}
}
@tidy columns var(--columns);
@tidy gap var(--gap) / true;
@tidy edge var(--edge);
@tidy site-max 75rem;
0.2.1
Removed
object-assign
) (#4)FAQs
PostCSS plugin to manage column and margin alignment.
The npm package postcss-tidy-columns receives a total of 185 weekly downloads. As such, postcss-tidy-columns popularity was classified as not popular.
We found that postcss-tidy-columns demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.
Security News
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.