LostGrid rules look like this:
And the processed CSS looks like this:
To create a basic horizontal grid, just insert some elements into any containing element like so and pass a fraction to the `lost-column` property. To unset (or remove) a column rule, possibly at a larger breakpoint, use `lost-column: none;`
lost-utility: clearfix;
is just a clearfix function since Lost Grid elements are floated. It’s a good idea to give this to the element wrapping your grid elements every time you have nested floated elements.
You can also make use of the `lost-center` property to assign a `max-width` and `margin: auto` to an element and center it on the page. `clearfix` will automatically be applied in this case.
Every element gets a float: left; and margin-right: gutter; applied to it except the last element in the row and the last item in a container. Lost will automatically detect the last item in a row (based on the denominator you passed) and apply a margin-right: 0;, and float: right; to it by default. To override this behavior and tell Lost to apply margin-right: 0; and float: right; to a specific iteration, simply pass a cycle param to your lost-column property as the second argument.
This will tell Lost to create div:nth-child(2n) { margin-right: 0; }
instead of div:nth-child(4n) { margin-right: 0; }
(like it would by default and break).
Using this knowledge we can create really flexible layouts with varying widths like so (this will work for a single row nicely).
There is a global setting to disable/enable cycle
by default. Just put @lost cycle auto;
or @lost cycle none;
at the top of your stylesheet.
It’s suggested that you learn the Lost shorthand syntax, but you can specify cycle (and other params) the verbose way with lost-column-cycle
.
The concept of cycle
is extremely important to Lost and what sets good Lost developers apart from great Lost developers.
Nesting is simple, but context is not supported. Nested elements are relative to their direct parent’s dimensions.
You can offset columns easily. To offset in the other direction, pass a negative fraction.
Note: the direction of the offset changed in Version 8 to be more natural. Read More
Easily align children elements with the `lost-align` property. It accepts options like `top-left`, `right`, `center`.
See lost-align for more details.
Use `lost-utility: edit;` on `body` to visualize the entire structure of your site, or just specify the areas you're working on. You can also set custom colors of your lost-utility: edit; declaration by adding an rgb value after `edit`.
Once you've mastered the basic horizontal grid system (it shouldn't take long), you can start to make vertical grids that have the same vertical gutters as your horizontal grids. Just use the `lost-row` property in place of `lost-column`. These rows will stretch to fill their container's height, so if you'd like to see them take up the full height of the page, set `height: 100%` on your container.
You can even make a horizontal/vertical grid (a waffle grid) which resembles a tic-tac-toe board.
You can easily change your grids to support Flexbox by altering the global at-rule variable `@lost flexbox` to `flex`. Once you do this, all grids throughout your site will use flexed elements. To make sure they are displayed as flexed elements, you need to wrap them in `lost-flex-container` or `lost-center` (which includes `lost-flex-container` by default).
Flexbox offers slightly cleaner output and avoids the use of clearfix
and other issues with float-based layouts. It also allows you to have elements of even height rather easily, and much more. The downside is, Flexbox doesn’t work in IE9 or below, so keep that in mind if you have a client that needs that kind of support.
Also note that waffle grids work well for the most part, but are somewhat finicky in fringe situations. All properties provide a way to disable or enable Flexbox per element with the flex
parameter so if you’d like to disable it for a specific case you could do this:
Lost supports masonry plugins like Isotope. To accomplish this we need to change how the margins work. Instead of applying a `margin-right` to everything, we need to apply it to both sides. We've made a couple special properties to help with this: `lost-masonry-column` which creates a margin on the left and right of each element it's applied to, and `lost-masonry-wrap` which wraps your columns and applies a negative margin to the left and right to them to help line them up with containing elements.
Lost uses PostCSS which means to override global variables we need to use something called `at-rules`. They're easy enough. Just define them at the top of your stylesheet and you're good to go.
gutter
accepts any unit value. 30px
(default).flexbox
accepts flex
or no-flex
(default).cycle
accepts none
or any digit (although this is really weird). auto
by default.clearing
accepts left
or both
(default).
rounder
accepts any number, decimal or whole.--beta-direction
accepts “rtl” and offers initial support of Right-to-Left for lost-column
and lost-waffle
. This support is a “beta” feature and should be expected to change. Please submit any issues or suggestions as an issue. Thanks!Sometimes you might want to use a custom unit with lost-column
, lost-row
, or lost-waffle
.
Learn more by reading the property: lost-unit
The “rounder” setting is used to fine tune your width of the container based on what browsers you intend to have computability with and how nested the container you’re targeting is.
You can fine tune the global setting of the “rounder” if you are not intending to target some of the browsers that can have a hard time with rounding 1/3 of 100%. This is done with a global @lost
rule.
If you want to do this on a per-element basis, you can do that too! This allows you to fine-tune exactly what you need for the situation. This could be if it’s nested deeply and you’re finding that browsers are not rounding correctly.
LostGrid is currently testing a beta version of Right-to-Left support.
To take advantage of the right-to-left grids it is presently only a global option for all grids. It is prefixed with --beta
in order to help guide the final API’s design.
Align nested elements. Apply this to a parent container.
reset | horizontal | vertical | top-left | top-center | top | top-right | middle-left | left | middle-center | center | middle-right | right | bottom-left | bottom-center | bottom | bottom-right |
The position the nested element takes relative to the containing element. |
flex | no-flex |
Determines whether this element should use Flexbox or not. |
Horizontally center a container element and apply padding to it.
max-width |
A max-width to assign. Can be any unit or a fraction of the containing element. |
padding |
Adds padding to the left and right of the generated container |
flex | no-flex |
(no-flex is default) Determines whether this element should use Flexbox or not. |
Creates a column that is a fraction of the size of its containing element's width with a gutter.
fraction |
This is a simple fraction of the containing element's width. |
cycle |
Lost works by assigning a margin-right to all elements except the last in the row. It does this by default by using the denominator of the fraction you pick. To override the default use this param., e.g.: .foo { lost-column: 2/4 2; } |
gutter |
The margin on the right side of the element used to create a gutter. Typically this is left alone and settings.gutter will be used, but you can override it here if you want certain elements to have a particularly large or small gutter (pass 0 for no gutter at all). Note: When specifying the gutter, you need to also specify the cycle. |
flex | no-flex |
Determines whether this element should use Flexbox or not. |
none |
Resets the column (back to browser defaults) |
Creates a flexbox container.
row | column |
The flex-direction the container should create. This is typically opposite to the element you're creating so a row would need `lost-flex-container: column;`. |
Creates a column for working with JS masonry libraries like Isotope. Assigns a margin to each side of the element.
flex | no-flex |
Determines whether this element should use Flexbox or not. |
gutter |
How large the gutter involved is, typically this won't be adjusted and will inherit settings.gutter, but it's made available if you want your masonry grid to have a special gutter, it should match your masonry-row's gutter. |
Creates a wrapping element for working with JS Masonry libraries like Isotope. Assigns a negative margin on each side of this wrapping element.
flex | no-flex |
Determines whether this element should use Flexbox or not. |
gutter |
How large the gutter involved is, typically this won't be adjusted and will inherit settings.gutter, but it's made available if you want your masonry grid to have a special gutter, it should match your masonry-column's gutter. |
Source ordering. Shift elements left, right, up, or down, by their left or top position by passing a positive or negative fraction.
fraction |
Fraction of the container to be shifted. |
row | column |
Direction the grid is going. Should be the opposite of the column or row it's being used on. |
gutter |
Adjust the size of the gutter for this movement. Should match the element's gutter. |
If the gutter within the selector is set by lost-column
or lost-row
then it will be retained in the lost-move
output unless the gutter is explicitly set by lost-move
or lost-move-gutter
.
Margin to the left, right, bottom, or top, of an element depending on if the fraction passed is positive or negative. It works for both horizontal and vertical grids but not both at the same time.
fraction |
Fraction of the container to be offset. |
row | column |
Direction the grid is going. Should be the opposite of the column or row it's being used on. Defaults to row. |
gutter |
How large the gutter involved is, typically this won't be adjusted, but if you have set the elements for that container to have different gutters than default, you will need to match that gutter here as well. |
clear | clear-left | clear-right | clear-top | clear-bottom |
If you are needing to clear an offset, like within a media query, you can do that using the clear parameter. `clear` with clear both left and right margin or top and bottom margin depending on the offset's direction. |
Note: the direction of the offset changed in Version 8 to be more natural. Read More
Creates a row that is a fraction of the size of its containing element's height with a gutter.
fraction |
This is a simple fraction of the containing element's height. |
gutter |
The margin on the bottom of the element used to create a gutter. Typically this is left alone and settings.gutter will be used, but you can override it here if you want certain elements to have a particularly large or small gutter (pass 0 for no gutter at all). Note: When specifying the gutter, you need to also specify the cycle. |
flex | no-flex |
Determines whether this element should use Flexbox or not. |
none |
Resets the row (back to browser defaults) |
Allows for a custom unit to be specified for `lost-column`, `lost-row`, and `lost-waffle`
unit |
`%` is default, `vh`, or `vw` pending the property. |
A general utility toolbelt for LostGrid. Included are mixins that require no additional input other than being called.
edit |
This will add a semi-transparent overlay |
edit rgb(r,g,b) |
Will use a custom color for the edit overlay |
edit rgba(r,g,b,a) |
Will use a custom color for the edit overlay. Alpha value is discarded and fixed at 0.1 |
edit #09AF00 |
Will use a custom color for the edit overlay. |
edit #09AF00BB |
Will use a custom color for the edit overlay. Alpha value is discarded and fixed at 0.1 |
clearfix |
Adds a clearfix mixin. |
overlay [max-width] [columns] [gutter] [color] |
This will add a semi-transparent full grid overlay. Use same units for max-width and gutter. |
Creates a block that is a fraction of the size of its containing element's width AND height with a gutter on the right and bottom.
fraction |
This is a simple fraction of the containing element's width and height. |
cycle |
Lost works by assigning a margin-right/bottom to all elements except the last row (no margin-bottom) and the last column (no margin-right). It does this by default by using the denominator of the fraction you pick. To override this default use this param., e.g.: .foo { lost-waffle: 2/4 2; } |
gutter |
The margin on the right and bottom side of the element used to create a gutter. Typically this is left alone and the global $gutter will be used, but you can override it here if you want certain elements to have a particularly large or small gutter (pass 0 for no gutter at all). |
flex | no-flex |
Determines whether this element should use Flexbox or not. |
float-right |
Tells LostGrid to float the last element in the cycle to the right. `lost-waffle` floats all elements left by default. |
These are to be used as values.
Allows you to output the gutter that is declared locally within the declaration.
⚠️ This variable is planning to be deprecated soon. Use lost-vars instead.
$lost-gutter-local |
Outputs the value of the gutter for that particular declaration. |
lost-column
lost-waffle
lost-row
lost-offset
lost-center
lost-masonry-wrap
lost-masonry-column
Use the global gutter anywhere in the project to help consistency and readability.
⚠️ This variable is planning to be deprecated soon. Use lost-vars instead.
$lost-gutter |
Outputs the value of the global gutter. Use this as a value anywhere in your project. |
Use to output Lost Variables anywhere in the project to help consistency and readability.
gutter |
Outputs the value of the global gutter. Use this anywhere in your project. |
gutter-local |
Outputs the value of the gutter for that particular declaration. |
lost-column
, look into adding box-sizing: border-box
See Issue 118
lost-column: ~"1/2";
.If you’re using Less in version <2.6
you need to escape any @lost
declarations like so: See Issue 197
calc()
to create the grid. Thus, LostGrid is limited to browsers that support calc()
. The great thing is that calc()
is widely supported in all current browsers and the LostGrid usage of calc()
is supported as far back as IE9+.calc()
support as IE10 except for background position which LostGrid doesn’t affect)