blob: 8a6e1e7629441188648cee7197354b09e30b7e7a [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001
2
3
4<h2 id="introduction">Introduction</h2>
5<p>The Material Design Lite (MDL) <strong>grid</strong> component is a simplified method for laying out content for multiple screen sizes. It reduces the usual coding burden required to correctly display blocks of content in a variety of display conditions.</p>
6<p>The MDL grid is defined and enclosed by a container element. A grid has 12 columns in the desktop screen size, 8 in the tablet size, and 4 in the phone size, each size having predefined margins and gutters. Cells are laid out sequentially in a row, in the order they are defined, with some exceptions:</p>
7<ul>
8<li>If a cell doesn&#39;t fit in the row in one of the screen sizes, it flows into the following line.</li>
9<li>If a cell has a specified column size equal to or larger than the number of columns for the current screen size, it takes up the entirety of its row.</li>
10</ul>
11<p>You can set a maximum grid width, after which the grid stays centered with padding on either side, by setting its <code>max-width</code> CSS property.</p>
12<p>Grids are a fairly new and non-standardized feature in most user interfaces, and provide users with a way to view content in an organized manner that might otherwise be difficult to understand or retain. Their design and use is an important factor in the overall user experience.</p>
13<h3 id="to-include-an-mdl-grid-component-">To include an MDL <strong>grid</strong> component:</h3>
14<p>&nbsp;1. Code a <code>&lt;div&gt;</code> element; this is the &quot;outer&quot; container, intended to hold all of the grid&#39;s cells. Style the div as desired (colors, font size, etc.).</p>
15<pre><code class="lang-html">&lt;div&gt;
16&lt;/div&gt;
17</code></pre>
18<p>&nbsp;2. Add the <code>mdl-grid</code> MDL class to the div using the <code>class</code> attribute.</p>
19<pre><code>&lt;div class=&quot;mdl-grid&quot;&gt;
20&lt;/div&gt;
21</code></pre><p>&nbsp;3. For each cell, code one &quot;inner&quot; div, including the text to be displayed.</p>
22<pre><code class="lang-html">&lt;div class=&quot;mdl-grid&quot;&gt;
23 &lt;div&gt;Content&lt;/div&gt;
24 &lt;div&gt;goes&lt;/div&gt;
25 &lt;div&gt;here&lt;/div&gt;
26&lt;/div&gt;
27</code></pre>
28<p>&nbsp;4. Add the <code>mdl-cell</code> class and an <code>mdl-cell--COLUMN-col</code> class, where COLUMN specifies the column size for the cell, to the &quot;inner&quot; divs using the <code>class</code> attribute.</p>
29<pre><code class="lang-html">&lt;div class=&quot;mdl-grid&quot;&gt;
30 &lt;div class=&quot;mdl-cell mdl-cell--4-col&quot;&gt;Content&lt;/div&gt;
31 &lt;div class=&quot;mdl-cell mdl-cell--4-col&quot;&gt;goes&lt;/div&gt;
32 &lt;div class=&quot;mdl-cell mdl-cell--4-col&quot;&gt;here&lt;/div&gt;
33&lt;/div&gt;
34</code></pre>
35<p>&nbsp;5. Optionally add an <code>mdl-cell--COLUMN-col-DEVICE</code> class, where COLUMN specifies the column size for the cell on a specific device, and DEVICE specifies the device type.</p>
36<pre><code class="lang-html">&lt;div class=&quot;mdl-grid&quot;&gt;
37 &lt;div class=&quot;mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet&quot;&gt;Content&lt;/div&gt;
38 &lt;div class=&quot;mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet&quot;&gt;goes&lt;/div&gt;
39 &lt;div class=&quot;mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet&quot;&gt;here&lt;/div&gt;
40&lt;/div&gt;
41</code></pre>
42<p>The grid component is ready for use.</p>
43<h4 id="examples">Examples</h4>
44<p>A grid with five cells of column size 1.</p>
45<pre><code class="lang-html">&lt;div class=&quot;mdl-grid&quot;&gt;
46 &lt;div class=&quot;mdl-cell mdl-cell--1-col&quot;&gt;CS 1&lt;/div&gt;
47 &lt;div class=&quot;mdl-cell mdl-cell--1-col&quot;&gt;CS 1&lt;/div&gt;
48 &lt;div class=&quot;mdl-cell mdl-cell--1-col&quot;&gt;CS 1&lt;/div&gt;
49 &lt;div class=&quot;mdl-cell mdl-cell--1-col&quot;&gt;CS 1&lt;/div&gt;
50 &lt;div class=&quot;mdl-cell mdl-cell--1-col&quot;&gt;CS 1&lt;/div&gt;
51&lt;/div&gt;
52</code></pre>
53<p>A grid with three cells, one of column size 6, one of column size 4, and one of column size 2.</p>
54<pre><code class="lang-html">&lt;div class=&quot;mdl-grid&quot;&gt;
55 &lt;div class=&quot;mdl-cell mdl-cell--6-col&quot;&gt;CS 6&lt;/div&gt;
56 &lt;div class=&quot;mdl-cell mdl-cell--4-col&quot;&gt;CS 4&lt;/div&gt;
57 &lt;div class=&quot;mdl-cell mdl-cell--2-col&quot;&gt;CS 2&lt;/div&gt;
58&lt;/div&gt;
59</code></pre>
60<p>A grid with three cells of column size 6 that will display as column size 8 on a tablet device.</p>
61<pre><code class="lang-html">&lt;div class=&quot;mdl-grid&quot;&gt;
62 &lt;div class=&quot;mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet&quot;&gt;CS 6 (8 on tablet)&lt;/div&gt;
63 &lt;div class=&quot;mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet&quot;&gt;CS 6 (8 on tablet)&lt;/div&gt;
64 &lt;div class=&quot;mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet&quot;&gt;CS 6 (8 on tablet)&lt;/div&gt;
65&lt;/div&gt;
66</code></pre>
67<p>A grid with four cells of column size 2 that will display as column size 4 on a phone device.</p>
68<pre><code class="lang-html">&lt;div class=&quot;mdl-grid&quot;&gt;
69 &lt;div class=&quot;mdl-cell mdl-cell--2-col mdl-cell--4-col-phone&quot;&gt;CS 2 (4 on phone)&lt;/div&gt;
70 &lt;div class=&quot;mdl-cell mdl-cell--2-col mdl-cell--4-col-phone&quot;&gt;CS 2 (4 on phone)&lt;/div&gt;
71 &lt;div class=&quot;mdl-cell mdl-cell--2-col mdl-cell--4-col-phone&quot;&gt;CS 2 (4 on phone)&lt;/div&gt;
72 &lt;div class=&quot;mdl-cell mdl-cell--2-col mdl-cell--4-col-phone&quot;&gt;CS 2 (4 on phone)&lt;/div&gt;
73&lt;/div&gt;
74</code></pre>
75<h2 id="configuration-options">Configuration options</h2>
76<p>The MDL CSS classes apply various predefined visual enhancements and behavioral effects to the grid. The table below lists the available classes and their effects.</p>
77<table>
78<thead>
79<tr>
80<th>MDL class</th>
81<th>Effect</th>
82<th>Remarks</th>
83</tr>
84</thead>
85<tbody>
86<tr>
87<td><code>mdl-grid</code></td>
88<td>Defines a container as an MDL grid component</td>
89<td>Required on &quot;outer&quot; div element</td>
90</tr>
91<tr>
92<td><code>mdl-cell</code></td>
93<td>Defines a container as an MDL cell</td>
94<td>Required on &quot;inner&quot; div elements</td>
95</tr>
96<tr>
97<td><code>mdl-grid--no-spacing</code></td>
98<td>Modifies the grid cells to have no margin between them.</td>
99<td>Optional on grid container.</td>
100</tr>
101<tr>
102<td><code>mdl-cell--N-col</code></td>
103<td>Sets the column size for the cell to N</td>
104<td>N is 1-12 inclusive, defaults to 4; optional on &quot;inner&quot; div elements</td>
105</tr>
106<tr>
107<td><code>mdl-cell--N-col-desktop</code></td>
108<td>Sets the column size for the cell to N in desktop mode only</td>
109<td>N is 1-12 inclusive; optional on &quot;inner&quot; div elements</td>
110</tr>
111<tr>
112<td><code>mdl-cell--N-col-tablet</code></td>
113<td>Sets the column size for the cell to N in tablet mode only</td>
114<td>N is 1-8 inclusive; optional on &quot;inner&quot; div elements</td>
115</tr>
116<tr>
117<td><code>mdl-cell--N-col-phone</code></td>
118<td>Sets the column size for the cell to N in phone mode only</td>
119<td>N is 1-4 inclusive; optional on &quot;inner&quot; div elements</td>
120</tr>
121<tr>
122<td><code>mdl-cell--N-offset</code></td>
123<td>Adds N columns of whitespace before the cell</td>
124<td>N is 1-11 inclusive; optional on &quot;inner&quot; div elements</td>
125</tr>
126<tr>
127<td><code>mdl-cell--N-offset-desktop</code></td>
128<td>Adds N columns of whitespace before the cell in desktop mode</td>
129<td>N is 1-11 inclusive; optional on &quot;inner&quot; div elements</td>
130</tr>
131<tr>
132<td><code>mdl-cell--N-offset-tablet</code></td>
133<td>Adds N columns of whitespace before the cell in tablet mode</td>
134<td>N is 1-7 inclusive; optional on &quot;inner&quot; div elements</td>
135</tr>
136<tr>
137<td><code>mdl-cell--N-offset-phone</code></td>
138<td>Adds N columns of whitespace before the cell in phone mode</td>
139<td>N is 1-3 inclusive; optional on &quot;inner&quot; div elements</td>
140</tr>
141<tr>
142<td><code>mdl-cell--order-N</code></td>
143<td>Reorders cell to position N</td>
144<td>N is 1-12 inclusive; optional on &quot;inner&quot; div elements</td>
145</tr>
146<tr>
147<td><code>mdl-cell--order-N-desktop</code></td>
148<td>Reorders cell to position N when in desktop mode</td>
149<td>N is 1-12 inclusive; optional on &quot;inner&quot; div elements</td>
150</tr>
151<tr>
152<td><code>mdl-cell--order-N-tablet</code></td>
153<td>Reorders cell to position N when in tablet mode</td>
154<td>N is 1-12 inclusive; optional on &quot;inner&quot; div elements</td>
155</tr>
156<tr>
157<td><code>mdl-cell--order-N-phone</code></td>
158<td>Reorders cell to position N when in phone mode</td>
159<td>N is 1-12 inclusive; optional on &quot;inner&quot; div elements</td>
160</tr>
161<tr>
162<td><code>mdl-cell--hide-desktop</code></td>
163<td>Hides the cell when in desktop mode</td>
164<td>Optional on &quot;inner&quot; div elements</td>
165</tr>
166<tr>
167<td><code>mdl-cell--hide-tablet</code></td>
168<td>Hides the cell when in tablet mode</td>
169<td>Optional on &quot;inner&quot; div elements</td>
170</tr>
171<tr>
172<td><code>mdl-cell--hide-phone</code></td>
173<td>Hides the cell when in phone mode</td>
174<td>Optional on &quot;inner&quot; div elements</td>
175</tr>
176<tr>
177<td><code>mdl-cell--stretch</code></td>
178<td>Stretches the cell vertically to fill the parent</td>
179<td>Default; optional on &quot;inner&quot; div elements</td>
180</tr>
181<tr>
182<td><code>mdl-cell--top</code></td>
183<td>Aligns the cell to the top of the parent</td>
184<td>Optional on &quot;inner&quot; div elements</td>
185</tr>
186<tr>
187<td><code>mdl-cell--middle</code></td>
188<td>Aligns the cell to the middle of the parent</td>
189<td>Optional on &quot;inner&quot; div elements</td>
190</tr>
191<tr>
192<td><code>mdl-cell--bottom</code></td>
193<td>Aligns the cell to the bottom of the parent</td>
194<td>Optional on &quot;inner&quot; div elements</td>
195</tr>
196</tbody>
197</table>
198
199