Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@material/layout-grid

Package Overview
Dependencies
Maintainers
15
Versions
1660
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@material/layout-grid

The Material Components for the web layout grid component

  • 15.0.0-canary.4ac393164.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
627K
decreased by-17.31%
Maintainers
15
Weekly downloads
 
Created
Source

Layout Grid

Material design’s responsive UI is based on a column-variate grid layout. It has 12 columns on desktop, 8 columns on tablet and 4 columns on phone.

Design & API Documentation

  • Material Design guidelines: Layout grid
  • Demo

Installation

npm install @material/layout-grid

Usage

HTML Structure

<div class="mdc-layout-grid">
  <div class="mdc-layout-grid__inner">
    <div class="mdc-layout-grid__cell"></div>
    <div class="mdc-layout-grid__cell"></div>
    <div class="mdc-layout-grid__cell"></div>
  </div>
</div>
Nested grid

When your contents need extra structure that cannot be supported by single layout grid, you can nest layout grid within each other. To nest layout grid, add a new mdc-layout-grid__inner to wrap around nested mdc-layout-grid__cell within an existing mdc-layout-grid__cell.

The nested layout grid behaves exactly like when they are not nested, e.g, they have 12 columns on desktop, 8 columns on tablet and 4 columns on phone. They also use the same gutter size as their parents, but margins are not re-introduced since they are living within another cell.

However, the Material Design guidelines do not recommend having a deeply nested grid as it might mean an over complicated UX.

<div class="mdc-layout-grid">
  <div class="mdc-layout-grid__inner">
    <div class="mdc-layout-grid__cell">
      <div class="mdc-layout-grid__inner">
        <div class="mdc-layout-grid__cell"><span>Second level</span></div>
        <div class="mdc-layout-grid__cell"><span>Second level</span></div>
      </div>
    </div>
    <div class="mdc-layout-grid__cell">First level</div>
    <div class="mdc-layout-grid__cell">First level</div>
  </div>
</div>

Styles

@use "@material/layout-grid/mdc-layout-grid";

CSS Classes

CSS ClassDescription
mdc-layout-gridMandatory, for the layout grid element
mdc-layout-grid__innerMandatory, for wrapping grid cell
mdc-layout-grid__cellMandatory, for the layout grid cell
mdc-layout-grid__cell--span-<NUMBER_OF_COLUMNS>Optional, specifies the number of columns the cell spans
mdc-layout-grid__cell--span-<NUMBER_OF_COLUMNS>-<TYPE_OF_DEVICE>Optional, specifies the number of columns the cell spans on a type of device (desktop, tablet, phone)
mdc-layout-grid__cell--order-<INDEX>Optional, specifies the order of the cell
mdc-layout-grid__cell--align-<POSITION>Optional, specifies the alignment of cell
mdc-layout-grid--fixed-column-widthOptional, specifies the grid should have fixed column width
mdc-layout-grid--align-<GRID_POSITION>Optional, specifies the alignment of the whole grid
mdc-layout-grid__cell--span-<NUMBER_OF_COLUMNS>

You can set the cells span by applying one of the span classes, of the form mdc-layout-grid__cell--span-{columns}, where {columns} is an integer between 1 and 12. If the chosen span size is larger than the available number of columns at the current screen size, the cell behaves as if its chosen span size were equal to the available number of columns at that screen size. If the span classes are not set, mdc-layout-grid__cell will fallback to a default span size of 4 columns.

mdc-layout-grid__cell--span-<NUMBER_OF_COLUMNS>-<TYPE_OF_DEVICE>

The same as mdc-layout-grid__cell--span-<NUMBER_OF_COLUMNS> but for a specific type of device(desktop, tablet or phone).

mdc-layout-grid__cell--order-<INDEX>

By default, items are positioned in the source order. However, you can reorder them by using the mdc-layout-grid__cell--order-<INDEX> classes, where <INDEX> is an integer between 1 and 12. Please bear in mind that this may have an impact on accessibility, since screen readers and other tools tend to follow source order.

mdc-layout-grid__cell--align-<POSITION>

Items are defined to stretch, by default, taking up the height of their corresponding row. You can switch to a different behavior by using one of the mdc-layout-grid__cell--align-<POSITION> alignment classes, where <POSITION> is one of top, middle or bottom.

mdc-layout-grid--fixed-column-width

You can designate each column to have a certain width by using mdc-layout-grid--fixed-column-width modifier. The column width can be specified through sass map $mdc-layout-grid-column-width or css custom properties --mdc-layout-grid-column-width-{screen_size}. The column width is set to 72px on all devices by default.

mdc-layout-grid--align-<GRID_POSITION>

The grid is by default center aligned. You can add mdc-layout-grid--align-left or mdc-layout-grid--align-right modifier class to change this behavior. Note, these modifiers will have no effect when the grid already fills its container.

Sass Mixins

MixinDescription
mdc-layout-grid($size, $margin, $max-width)Generates CSS for a grid container on certain device type
mdc-layout-grid-inner($size, $margin, $gutter)Generates CSS for a grid cell wrapper on certain device type
mdc-layout-grid-cell($size, $default-span, $gutter)Generates CSS for a grid cell on certain device type
mdc-layout-grid-fixed-column-width($size, $margin, $gutter, $column-width)Generates CSS for a fixed column width container on certain device type
mdc-layout-grid-cell-order($order)Reorders a cell inside a grid
mdc-layout-grid-cell-align($position)Aligns a cell vertically inside a grid
mdc-layout-grid($size, $margin, $max-width)

Generates CSS for a grid container on certain device type. The mixin takes three parameters:

  • $size: the target platform: desktop, tablet or phone.
  • $margin: the size of the grid margin.
  • $max-width (optional): the maximum width of the grid, at which point space stops being distributed by the columns.
mdc-layout-grid-inner($size, $margin, $gutter)

Generates CSS for a grid cell wrapper on certain device type. The mixin takes three parameters:

  • $size: the target platform: desktop, tablet or phone.
  • $margin: the size of the grid margin.
  • $gutter: the size of the gutter between cells.
mdc-layout-grid-cell($size, $default-span, $gutter)

Generates CSS for a grid cell on certain device type. The mixin takes three parameters:

  • $size: the target platform: desktop, tablet or phone.
  • $default-span (optional, default 4): how many columns this cell should span (1 to 12).
  • $gutter: the size of the gutter between cells. Be sure to use the same value as for the parent grid.

Note even though size is passed in as one of the arguments, it won't apply any media-query rules. It is set for using the correct CSS custom properties to overriden the margin and gutter at runtime (See Margins and gutters section for detail).

mdc-layout-grid-fixed-column-width($size, $margin, $gutter, $column-width)

Generates CSS for a fixed column width container on certain device type. The mixin takes four parameters:

  • $size: the target platform: desktop, tablet or phone.
  • $margin: the size of the grid margin.
  • $gutter: the size of the gutter between cells.
  • $column-width: the width of the column within the grid.

Sass Variables

VariablesDescription
mdc-layout-grid-breakpointsA SASS Map specifies the breakpoints width
mdc-layout-grid-columnsA SASS Map specifies the number of columns
mdc-layout-grid-default-marginA SASS Map specifies the space between the edge of the grid and the edge of the first cell
mdc-layout-grid-default-gutterA SASS Map specifies the space between edges of adjacent cells
mdc-layout-grid-column-widthA SASS Map specifies the column width of grid columns
mdc-layout-grid-default-column-spanSpecifies a cell's default span
mdc-layout-grid-max-widthRestricts max width of the layout grid

CSS Custom Properties

CSS Custom PropertiesDescription
mdc-layout-grid-margin-<TYPE_OF_DEVICE>Specifies the space between the edge of the grid and the edge of the first cell
mdc-layout-grid-gutter-<TYPE_OF_DEVICE>Specifies the space between edges of adjacent cells

Keywords

FAQs

Package last updated on 16 Nov 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc