A small and simple CSS gutter to create rows and cells using the flexbox model.



A small and simple CSS gutter to create rows and cells using the flexbox model.
- Getting started
- Breakpoints
- Spaces
- Options
- Disabling the Gutter
- Fit one row
- Flexible width
- Customization
- Namespace
- Gutter size
- Breakpoints
- Rows number
- Order classes
- Spaces
- CSS custom properties
- Using custom classes
- Tracking the viewport
- Tracking the cell positions
- Help
This package is made for the use with Node and also for Composer.
Add __Bit&Black Rows__ to your project by running
- $ npm install bitandblack-rows or
- $ composer require bitandblack/rows
__Bit&Black Rows__ uses 12 units each row per default.
Add the class row to an HTML container tag. The cells should get the class row__cell. For example:
``html`
Use one of the modifier classes (like row__cell--cell2) to define how many units a cell will take. For example:
`html`
Uses 2 units.
Uses 6 units.
Uses 4 units.
Use classes like row__cell--rightMarginCell1 to define empty units to the left or to the right of a cell.
Use classes like row__cell--order2 to define the sort order of cells in case you want to use breakpoints and sort differently then.
__Bit&Black Rows__ supports the use of breakpoints. Those are defined as:
- phone: smaller than 600px tablet-portrait
- : 600pxtablet-landscape
- : 900pxdesktop
- : 1200pxdesktop-big
- : 1800px
Add them at the beginning of the modifiers class name. For example:
`html`
12 rows per default, 6 rows when device has the resolution of a tablet in portrait or wider, 4 rows when device has a desktop resolution
12 rows per default, 6 rows when device has the resolution of a tablet in portrait or wider, 4 rows when device has a desktop resolution
12 rows per default, 6 rows when device has the resolution of a tablet in portrait or wider, 4 rows when device has a desktop resolution
You can also use the breakpoints in SCSS by using some mixins, for example:
`scss
@use "~bitandblack-rows/src/scss/breakpoints";
div {
display: block;
@include breakpoints.tablet-landscape-up {
display: none;
}
}
`
There's a smell of Bootstrap and Tailwind in __Bit&Black Rows__: You can use some classes for adding margins and paddings. There are:
- m to set a margin from 0 to 5mx
- to set a margin-left and margin-right from 0 to 5my
- to set a margin-top and margin-bottom from 0 to 5mt
- to set a margin-top from 0 to 5mr
- to set a margin-right from 0 to 5mb
- to set a margin-bottom from 0 to 5ml
- to set a margin-left from 0 to 5p
- to set a padding from 0 to 5px
- to set a padding-left and padding-right from 0 to 5py
- to set a padding-top and padding-bottom from 0 to 5pt
- to set a padding-top from 0 to 5pr
- to set a padding-right from 0 to 5pb
- to set a padding-bottom from 0 to 5pl
- to set a padding-left from 0 to 5
So to add a margin-left with the value of 5rem, you need to add the class ml-5.
To define a margin or a padding dependent on a breakpoint, add the name of the breakpoint like mt-tablet-portrait-5.
If you need a negative margin, add a n. For example: mt-n-5 or mt-n-tablet-portrait-5.
Add the class row--gutter-disabled if you don't want to have a gutter at a specific place.
If you have an unknown number of cells or a number which doesn't matches your number of columns, add the class row--fit-row. The cells only need row__cell then and will result with the same width in one row.
``html``
Auto size, all cells in one row
Auto size, all cells in one row
Auto size, all cells in one row
Auto size, all cells in one row
Auto size, all cells in one row
Sometimes the cells need a flexible width. In this case add the class row__cell--width-flexible.
``html``
Auto width as wide as possible
Auto size fitting the content
You can change or remove the prefix if you want by changing the value of $bb-rows-namespace.
Use $bb-rows-gutter to define the size of your gutter.
The breakpoints are stored in $bb-rows-breakpoints which you can override if you want to.
The default rows number is set to 12. You can change this by overriding the $bb-rows-row-number.
Per default the number of order classes will be the same as the number of rows. If you need more of them you can define that by overriding $bb-rows-order-number.
All the space classes are using rem per default. The smallest unit is 1rem. You can change this by setting $bb-rows-spaces-unit to a different value.
Per default every setting has 6 steps from 0 to 5. If you need more of them you can change the value of $bb-rows-spaces-number.
Per default, __Bit&Black Rows__ uses CSS custom properties for its internal calculations. If you don't want to use them and prefer "traditional" CSS, you can disable this behaviour by setting $bb-rows-use-custom-css-properties to false.
If you want to use custom classes for your design system, you can use mixins to access all of __Bit&Black Rows__ functionalities.
Let's say there is a grid with a complex logic in it:
`html`
...
Then it could be rewritten like that:
`scss
// Bit&Black Rows needs to know the name of the child selector.
$rows-cell-selector: ".my-custom-cell";
@use "~bitandblack-rows/src/scss/variables" with (
$bb-rows-cell-selector: $rows-cell-selector,
);
@use "~bitandblack-rows/src/scss/base";
@use "~bitandblack-rows/src/scss/breakpoints";
.my-custom-grid {
@include base.grid;
@include base.grid--gutter-disabled;
#{$rows-cell-selector} {
@include base.cell;
@include base.cell--cell-count(10);
@include base.cell--left-margin-cell-count(2);
@include breakpoints.tablet-portrait-up {
@include base.cell--cell-count(8);
@include base.cell--left-margin-cell-count(4);
}
@include breakpoints.desktop-big-up {
@include base.cell--cell-count(6);
@include base.cell--left-margin-cell-count(6);
@include base.cell--order(2);
}
}
}
`
And the HTML would be:
`html`
...
__Bit&Black Rows__ gives a small script to track changes of the viewport. Use it like that:
``javascript
import { Viewport } from "bitandblack-rows";
const viewport = new Viewport();
viewport.onResize((viewportName) => {
console.log(Viewport is currently defined as "${viewportName}");``
});
It is possible to track the cell positions in the grid. This allows handling outside laying cells or the cells in each corner of the grid.
``javascript
import { Position } from "bitandblack-rows";
const position = new Position();
position.add(
document.querySelector(".row")
);
``
Per default, CSS classes will be added to all outside laying cells. This can be changed with position.setAddCssClassesForOutsideCells(false). The class names can also be changed.
Additionally, data attributes can be added to all cells, providing information about their position in the grid. This is disabled per default and can be enabled with position.setAddDataAttributesAboutCellPositions(true).
If you have any questions feel free to contact us under hello@bitandblack.com`.
Further information about Bit&Black can be found under www.bitandblack.com.