Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame^] | 1 | |
| 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'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> 1. Code a <code><div></code> element; this is the "outer" container, intended to hold all of the grid's cells. Style the div as desired (colors, font size, etc.).</p> |
| 15 | <pre><code class="lang-html"><div> |
| 16 | </div> |
| 17 | </code></pre> |
| 18 | <p> 2. Add the <code>mdl-grid</code> MDL class to the div using the <code>class</code> attribute.</p> |
| 19 | <pre><code><div class="mdl-grid"> |
| 20 | </div> |
| 21 | </code></pre><p> 3. For each cell, code one "inner" div, including the text to be displayed.</p> |
| 22 | <pre><code class="lang-html"><div class="mdl-grid"> |
| 23 | <div>Content</div> |
| 24 | <div>goes</div> |
| 25 | <div>here</div> |
| 26 | </div> |
| 27 | </code></pre> |
| 28 | <p> 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 "inner" divs using the <code>class</code> attribute.</p> |
| 29 | <pre><code class="lang-html"><div class="mdl-grid"> |
| 30 | <div class="mdl-cell mdl-cell--4-col">Content</div> |
| 31 | <div class="mdl-cell mdl-cell--4-col">goes</div> |
| 32 | <div class="mdl-cell mdl-cell--4-col">here</div> |
| 33 | </div> |
| 34 | </code></pre> |
| 35 | <p> 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"><div class="mdl-grid"> |
| 37 | <div class="mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet">Content</div> |
| 38 | <div class="mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet">goes</div> |
| 39 | <div class="mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet">here</div> |
| 40 | </div> |
| 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"><div class="mdl-grid"> |
| 46 | <div class="mdl-cell mdl-cell--1-col">CS 1</div> |
| 47 | <div class="mdl-cell mdl-cell--1-col">CS 1</div> |
| 48 | <div class="mdl-cell mdl-cell--1-col">CS 1</div> |
| 49 | <div class="mdl-cell mdl-cell--1-col">CS 1</div> |
| 50 | <div class="mdl-cell mdl-cell--1-col">CS 1</div> |
| 51 | </div> |
| 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"><div class="mdl-grid"> |
| 55 | <div class="mdl-cell mdl-cell--6-col">CS 6</div> |
| 56 | <div class="mdl-cell mdl-cell--4-col">CS 4</div> |
| 57 | <div class="mdl-cell mdl-cell--2-col">CS 2</div> |
| 58 | </div> |
| 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"><div class="mdl-grid"> |
| 62 | <div class="mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet">CS 6 (8 on tablet)</div> |
| 63 | <div class="mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet">CS 6 (8 on tablet)</div> |
| 64 | <div class="mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet">CS 6 (8 on tablet)</div> |
| 65 | </div> |
| 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"><div class="mdl-grid"> |
| 69 | <div class="mdl-cell mdl-cell--2-col mdl-cell--4-col-phone">CS 2 (4 on phone)</div> |
| 70 | <div class="mdl-cell mdl-cell--2-col mdl-cell--4-col-phone">CS 2 (4 on phone)</div> |
| 71 | <div class="mdl-cell mdl-cell--2-col mdl-cell--4-col-phone">CS 2 (4 on phone)</div> |
| 72 | <div class="mdl-cell mdl-cell--2-col mdl-cell--4-col-phone">CS 2 (4 on phone)</div> |
| 73 | </div> |
| 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 "outer" 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 "inner" 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 "inner" 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 "inner" 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 "inner" 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 "inner" 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 "inner" 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 "inner" 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 "inner" 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 "inner" 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 "inner" 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 "inner" 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 "inner" 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 "inner" 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 "inner" 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 "inner" 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 "inner" 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 "inner" 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 "inner" 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 "inner" 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 "inner" div elements</td> |
| 195 | </tr> |
| 196 | </tbody> |
| 197 | </table> |
| 198 | |
| 199 | |