You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 13, 2025. It is now read-only.
BREAKING CHANGE: the css custom properties for customize margins and gutters are exposed in format of `mdc-layout-grid-margin-#{$size}`, where valid sizes are `desktop`, `tablet` and `phone`. The old name `mdc-layout-grid-margin` and `mdc-layout-grid-gutter` is no longer available in the new version. Sass variables change from single numeric value to Sass map to accomendate margins and gutters for different screens as well. Visually, the default value of margins and gutters change from 16px to 24px on desktop, while remain the same on tablet and mobile.
Copy file name to clipboardExpand all lines: packages/mdc-layout-grid/README.md
+36-25Lines changed: 36 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,9 +48,7 @@ there isn't enough room for a cell, it gets moved to the beginning of the next r
48
48
The grid has 12 columns in desktop mode (>= 840px), 8 columns in tablet mode (>= 480px), and 4 columns in phone mode
49
49
(< 480px). Column widths are variable; margins and gutters are fixed, with columns taking up the remainder of the space.
50
50
51
-
Margins (the space between the edge of the grid and the edge of the first cell) and gutters (the space between edges of
52
-
adjacent cells) are user-definable, with the Material Design spec recommending 8px, 16px, 24px or 40px as the sizes to
53
-
choose from. The default margin and gutter are both 16px, but they don't have to be the same size.
51
+
Margins (the space between the edge of the grid and the edge of the first cell) and gutters (the space between edges of adjacent cells) can be customized on different devices respectively based on design needs. Layout grids set default margins and gutters to 24px on desktop, 16px on tablet and phone, according to the Material Design spec.
54
52
55
53
The grid and cells are not styled in any way, serving only for alignment and positioning of elements.
56
54
@@ -70,24 +68,36 @@ Behavior for grids containing direct children without the `mdc-layout-grid__cell
70
68
71
69
### Margins and gutters
72
70
73
-
The default size for both the margins and gutters in MDC layout grid is 16px.
71
+
Layout grids set default margins and gutters to 24px on desktop, 16px on tablet and phone.
74
72
75
-
You can change the margins and gutters for a grid using the `--mdc-layout-grid-margin` and `--mdc-layout-grid-gutter`
76
-
custom properties, respectively. This requires support for CSS custom properties on the end-user's browser.
73
+
The Material Design spec recommends 8px, 16px, 24px or 40px as the sizes to choose from, we set those as choices in our demo catalog. However, MDC layout grid doesn't impose any restrictions.
77
74
78
-
The Material Design spec recommends 8px, 16px, 24px or 40px as the sizes to choose from, but MDC layout grid doesn't
79
-
impose any restrictions.
75
+
> Note: Due to the implementation of MDC layout grid, it's not possible to use a margin smaller than half of the size
76
+
of the gutter, in most browsers. As support for [CSS Grid](https://www.w3.org/TR/css-grid-1/) lands in browsers, this
77
+
limitation will go away, as MDC layout grid is progressively enhanced to support it.
78
+
79
+
80
+
#### CSS custom properties
81
+
82
+
You can change the margins and gutters for a grid using the `--mdc-layout-grid-margin-#{$device}` and `--mdc-layout-grid-gutter-#{$device}` custom properties, respectively. This requires support for CSS custom properties on the end-user's browser.
80
83
81
84
```css
82
85
.my-grid {
83
-
--mdc-layout-grid-margin: 40px;
84
-
--mdc-layout-grid-gutter: 16px;
86
+
--mdc-layout-grid-margin-desktop: 40px;
87
+
--mdc-layout-grid-gutter-tablet: 16px;
88
+
--mdc-layout-grid-gutter-phone: 8px;
85
89
}
86
90
```
87
91
88
-
> Note: Due to the implementation of MDC layout grid, it's not possible to use a margin smaller than half of the size
89
-
of the gutter, in most browsers. As support for [CSS Grid](https://www.w3.org/TR/css-grid-1/) lands in browsers, this
90
-
limitation will go away, as MDC layout grid is progressively enhanced to support it.
92
+
#### Sass variables
93
+
94
+
You can change the margins and gutters using sass variables if you are compiling from them. MDC layout grid uses sass map `mdc-layout-grid-default-margin` and `mdc-layout-grid-default-gutter` to define margins and gutters on different screen types.
95
+
96
+
97
+
### Max width
98
+
99
+
MDC layout grids take up the parent element space by default. However, user can set `$mdc-layout-grid-max-width` to restrict the max-width of the layout grid.
100
+
91
101
92
102
### Column spans
93
103
@@ -99,12 +109,10 @@ limitation will go away, as MDC layout grid is progressively enhanced to support
99
109
</div>
100
110
```
101
111
102
-
Cells have a default span size of 4 columns, with other sizes being possible by applying one of the span classes, of the
103
-
form `mdc-layout-grid__cell--span-{columns}`, where `{columns}` is an integer between 1 and 12.
112
+
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. That is, it takes up the entirety of its row, and no more than that.
113
+
114
+
If the span classes are not set, `mdc-layout-grid__cell` will fallback to a default span size of 4 columns. You can make it a different number by changing the default value. However, this number needs to be provided at compile time by using sass variable `$mdc-layout-grid-default-column-span`.
104
115
105
-
If the chosen span size is larger than the available number of columns at the current screen size, the cell behaves as
106
-
if its chosen span size were equal to the available number of columns at that screen size. That is, it takes up the
107
-
entirety of its row, and no more than that.
108
116
109
117
### Column spans for specific screen sizes
110
118
@@ -126,6 +134,7 @@ In the example above, the first cell has a default span of 6, the second 4, and
126
134
the first cell becomes 8 columns wide instead, and the second 6 columns wide. At phone sizes, the third cell becomes 4
127
135
columns wide.
128
136
137
+
129
138
### Reordering
130
139
131
140
By default, items are positioned in the source order. However, you can reorder them by using the
@@ -162,26 +171,28 @@ behavior by using one of the `mdc-layout-grid__cell--align-{position}` alignment
`mdc-layout-grid` defines a grid and should be applied to the container element. The mixin takes three parameters:
177
+
`mdc-layout-grid` defines a grid and should be applied to the container element. The mixin takes four parameters:
178
+
-`$size`: the target platform: `desktop`, `tablet` or `phone`.
169
179
-`$margin`: the size of the grid margin.
170
180
-`$gutter`: the size of the gutter between cells.
171
181
-`$max-width` (optional): the maximum width of the grid, at which point space stops being distributed by the columns.
172
182
173
-
Note that the margin and gutter can be overriden at runtime by using the CSS custom properties detailed in the
174
-
"Margins and gutters" section under "CSS class usage".
175
-
176
183
### mdc-layout-grid-cell
177
184
178
185
```scss
179
-
@includemdc-layout-grid-cell(16px, 4);
186
+
@includemdc-layout-grid-cell(desktop, 4, 16px);
180
187
```
181
188
182
189
`mdc-layout-grid-cell` defines a cell and should be applied to the cell element. The mixin takes two parameters:
190
+
-`$size`: the target platform: `desktop`, `tablet` or `phone`.
191
+
-`$default-span` (optional, default 4): how many columns this cell should span (1 to 12).
183
192
-`$gutter`: the size of the gutter between cells. Be sure to use the same value as for the parent grid.
184
-
-`$span` (optional, default 4): how many columns this cell should span (1 to 12).
193
+
194
+
> 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](#margins-and-gutters) section for detail).
0 commit comments