Mesh
The powerful Grid System for PostCSS
Table of contents
About Mesh
There are a lot of different grid systems already out there and most of them are pretty good. But ☝️ none of them is offering the whole bandwidth of possible options. E.g. I wanted to switch between a flex
, inline-block
or float
based grid as well as I wanted to be able to overwrite certain parameters like gutter or column-count breakpoint wise. That is how I came up with the idea to create my very own grid compiler and Mesh was born 🎉🎉🎉.
Getting Started
Installation
$ npm i postcss-mesh
Grid Setup
SCSS
Mesh is based on @-rules. To initiate a new grid use @mesh-grid
. All breakpoints for a grid should be nested within the respective grid declaration. See the example below for a simple grid setup with bootstrap standards.
@ @ @ @}
HTML
// This markup is a two column grid with equal widths // for all defined breakpoints.
Unique Selling Points
Responsive Gutter
Set the responsive-gutter property to true
to scale the gutter as your container grows. This makes your grid less static and more fluid. To make this feature work you have to set a viewport
context even in your default settings of the grid.
This feature inherits the gutter size for the first nested level only.
//////////@
Regular Gutter
Responsive Gutter
Gutter On Outside
Allows you to toggle the container's padding which is based on the gutter size.
////@
Mobile First || Desktop First
You can decide if your default viewport is a desktop one or a mobile one using the query-condition property. This property takes min-width
or max-width
as an argument. If set to min-width
your default viewport will be a mobile one. As soon as your screen's width hits the next bigger width defined in all of your breakpoints, it snaps to the related breakpoint.
////@
Unlimited Breakpoints
Bootstrap comes with five predefined breakpoints (Extra small <576px, Small ≥576px, Medium ≥768px, Large ≥992px, Extra Large ≥1200px). These breakpoints have proved its worth over time. But nevertheless, sometimes your design requires more individual breakpoints. In this case Mesh is your best friend. With Mesh you can define as many or as less custom breakpoints as you want using the @mesh-viewport-VIEWPORTNAME
-@-rule where VIEWPORTNAME
is the viewport's ID. The ID is used in the viewport specific classes. E.g. @mesh-viewport-lg
results in .mesh-column-lg
-classes.
////@
Property Overwrite
Property Overwrite allows you to overwrite some properties breakpoint wise, e.g. gutter
. Learn more about properties here.
//@
Custom Class Names
Overwrite the default classNames to keep them unique, short or both. See the properties list for the whole range of naming properties.
// this changes all selectors containing "column"// e.g. ".mesh-column-1" to ".mesh-col-1" @mesh-grid{ naming-column: col;}
Excluding
It's a fact: Most projects don't use the whole bandwith of available column-spans. This leads to many lines of unused CSS in the final bundle. Thanks to this feature it is possible to exclude certain column-spans for certain components viewport wise.
// this how you would exclude ".mesh-column-1" & ".mesh-column-2" @mesh-grid{ exclude-columns: 1,2;}
You can also exclude-pushes
, exclude-pulls
& exclude-offsets
. See the properties list for the whole range of excluding properties.
Components
Mesh's compiled Grid is made of three basic components and three transform components. The basic components describe the .mesh-container
, .mesh-void
& .mesh-column
classes. These components are necessary to set up a very basic grid. The transform components describe the .mesh-offset
, .mesh-pull
& .mesh-push
classes. These components are necessary to transform a column within your grid and should be added to a column component only. Using transform components you can reorder your columns.
Container
The container is the most outer component of a grid instance. It sets up the maximum width of the grid and should not be nested.
Void
The void component is the equivalent to Bootstrap's row
component and voids its parent's gutter. The only immediate child of a void component should be a column.
Column
The column component is where you can put your content. All columns should be an immediate child of a void component. Replace x
with a number between 1 and your given column-count.
<!--For breakpoint specific column widths include yourbreakpoint's ID in the class, e.g. 'mesh-column-lg-6'.-->
Offset
The offset component will add a margin to the respective column to create an even bigger gap between two columns. Using the component like below will offset the column about the width of a single column.
<!--For breakpoint specific column offsets include yourbreakpoint's ID in the class, e.g. 'mesh-offset-lg-1'.-->
Pull
The pull component will reposition the respective column from the right. Using the component like below will pull the column about the width of a single column to the left.
<!--For breakpoint specific column pulls include yourbreakpoint's ID in the class, e.g. 'mesh-pull-lg-1'.-->
Push
The push component will reposition the respective column from the left. Using the component like below will push the column about the width of a single column to the right.
<!--For breakpoint specific column pushes include yourbreakpoint's ID in the class, e.g. 'mesh-push-lg-1'.-->
Nesting
Of course you can also nest your columns.
<!--This is how you can nest columns within columns.If using "responsive-gutter" you can only go onelevel deep keeping the roots gutter size.-->
Ordering
Sometimes you have to switch position of certain columns breakpoint wise. Using push and pull components you can shift your columns.
<!--This markup moves the first column by the width ofthree columns to the right and the second columnby the width of nine columns to the left.-->
Properties
Mesh is based on a bunch of properties you can adjust to your needs. Some of them are overwriteable in each defined breakpoint. See the table below to get an overview of what Mesh is offering.
Property | Description | Options | Overwrite |
---|---|---|---|
column-align |
Aligns all columns at the top, middle or bottom of a void. | top || middle || bottom |
yes |
column-count |
Defines how many columns fit in one void. | number |
yes |
compile |
If set to false Mesh won't compile classes of the current grid. |
true || false |
no |
container-base-width-unit |
Defines the container's width unit. |
% || vw |
yes |
container-width |
Defines the container's max-width property for current viewport. |
px || % |
yes |
debug |
If set to true Mesh generates excluded classes and extends the style with debug-property of debug-value |
true || false |
no |
debug-property |
A valid CSS Property for debug style extension. |
e.g. border |
no |
debug-value |
A value for the given debug-property . |
e.g. 1px dotted red |
no |
display-type |
Defines if the grid is inline-block, float or flex based. | inline-block || float || flex |
no |
exclude-columns |
Given integers define spans to exclude from column classes. | int, int |
yes |
exclude-offsets |
Given integers define spans to exclude from offset classes. | int, int |
yes |
exclude-pulls |
Given integers define spans to exclude from pull classes. | int, int |
yes |
exclude-pushes |
Given integers define spans to exclude from push classes. | int, int |
yes |
gutter |
Sets the gap between columns. | px |
yes |
gutter-on-outside |
If set to false the container won't have a padding. |
true || false |
yes |
name |
Sets the grid's name and adjusts the component's class prefix. | string |
no |
naming-column |
Given string replaces column in all generated selectors. |
string |
no |
naming-container |
Given string replaces container in all generated selectors. |
string |
no |
naming-offset |
Given string replaces offset in all generated selectors. |
string |
no |
naming-pull |
Given string replaces pull in all generated selectors. |
string |
no |
naming-push |
Given string replaces push in all generated selectors. |
string |
no |
naming-void |
Given string replaces void in all generated selectors. |
string |
no |
query-condition |
Using this property you can decide if you want the compiled styles to be mobile first or desktop first. | min-width || max-width |
no |
responsive-gutter |
If set to true the gutter scales as the container grows. |
true || false |
yes |
use-name-prefix |
If set to false Mesh won't use the grid's name as a class prefix. |
true || false |
no |
viewport |
Defines the screen's width at which a new media-query should be initiated. | px |
yes |