A custom element and a style useful to create responsive and fluid grid layouts.
For this purpose this package provides a custom element - matrix-layout - and a shared style - matrix-style.
The matrix-layout is an element wrapping and using matrix-style providing responsiveness and frameless mode for your grid layouts.
The matrix-style is an helper style useful for creating your own grid layouts using CSS custom properties and CSS mixins it provides.
Because custom properties can be defined inside a
@media rule, you can customize your grid layout for different responsive breakpoints.
Furthermore, since the only assumption it does is that you create a layout to use it, inserting within it some items in the light DOM it is completely decoupled from children elements.
It does not impose any constraint on child nodes.
So, you can use any element you want as child item.
See the demo directory to look at some implementations.
One way to install it is executing
bower install leodido/matrix-layout --save in your shell.
Or if you prefer
yarn add leodido/matrix-layout --save, since it is published on npm registry also.
matrix-style.html and include matrix-style in the style of an element's definition.
<!-- Include the style to use the CSS mixins and the CSS variables it provides. -->
Then define the style details of your grid layout via custom properties and mixin.
To all its slotted children will be applied the
So use can already use the
<awesome-lattice> custom element.
The demo directory contains more comprehensive examples.
In many cases, it's useful to expand an item more than 1 column.
We call such type of items wide items.
To achieve this type of irregular grid layout, first you have to specify within the style of your custom element the number of columns that such items should expand to.
How? Setting the custom property
To indicate which item should expand, apply the CSS mixin
This way you can also combine the expansibility of items with responsive breakpoints.
Otherwise simply use the provided attribute - i.e.,
wide - on the items in the light DOM.
Sometimes you want that your items maintain a given aspect ratio.
Also in this case we provide more ways to accomplish this result.
In any case we first need to setup the aspect ratio.
Then we can set the
has-aspect-ratio attribute on our layout element to male all the elements respect it.
Another approach is to selectively define the items that have to respect the aspect ratio.
One way to do it is applying the CSS mixin - i.e.,
--matrix-aspect-ratio-item - to items we want to keep the choosen aspect ratio.
Otherwise simply use the
aspect-ratio attribute on any item (in the light DOM) you want ...
This approaches are more flexible than the previous one since you can choose which items have to maintain the aspect ratio and which not.
||The number of columns per row.||1|
||The space between two items.||0px|
||The height of the items.||auto|
||The aspect ratio of the items.||1|
||The number of columns a wide item should expand to.||1|
||The styles to apply to the host we want to become a matrix layout.|
||The styles to apply to each item.|
||The styles to apply to wide items (includes
||The styles to apply to items with aspect ratio (includes
||The styles to apply to the container within the layout to remove side spaces from it.|