Debian Codegraph @

docs/grids.md

raw
1 (sd-grids)=
2
3 # Grids
4
5 ## Introduction
6
7 Grids are based on a 12 column system, which can adapt to the size of the viewing screen.
8
9 A `grid` directive can be set with the number of default columns (1 to 12);
10 either a single number for all screen sizes, or four numbers for extra-small (<576px), small (768px), medium (992px) and large screens (>1200px),
11 then child `grid-item` directives should be set for each item.
12
13 Try re-sizing the screen to see the number of columns change:
14
15 ::::{grid} 1 2 3 4
16 :outline:
17
18 :::{grid-item}
19 A
20 :::
21 :::{grid-item}
22 B
23 :::
24 :::{grid-item}
25 C
26 :::
27 :::{grid-item}
28 D
29 :::
30 ::::
31
32 `````{dropdown-syntax}
33
34 ````{tab-set-code}
35 ```{literalinclude} ./snippets/myst/grid-basic.txt
36 :language: markdown
37 ```
38 ```{literalinclude} ./snippets/rst/grid-basic.txt
39 :language: rst
40 ```
41 ````
42 `````
43
44 You can also use the `auto` value for the column width(s), to size columns based on the natural width of their content.
45
46 ::::{grid} auto
47
48 :::{grid-item}
49 :outline:
50 :padding: 2
51
52 short text content
53 :::
54 :::{grid-item}
55 :outline:
56 :padding: 2
57
58 some longer text content
59 :::
60 :::{grid-item}
61 :outline:
62 :padding: 2
63
64 short text content
65 :::
66 ::::
67
68 ## Placing a card in a grid
69
70 The `grid-item-card` directive is a short-hand for placing a card content container inside a grid item (see [Cards](./cards.md)). Most of the `card` directive's options can be used also here:
71
72 ::::{grid} 2
73 :::{grid-item-card} Title 1
74 A
75 :::
76 :::{grid-item-card} Title 2
77 B
78 :::
79 ::::
80
81 `````{dropdown-syntax}
82
83 ````{tab-set-code}
84 ```{literalinclude} ./snippets/myst/grid-card.txt
85 :language: markdown
86 ```
87 ```{literalinclude} ./snippets/rst/grid-card.txt
88 :language: rst
89 ```
90 ````
91 `````
92
93 ## Controlling spacing between items
94
95 You can set the spacing between grid items with the `gutter` option.
96 Like for grid columns, you can either provide a single number or four for small, medium and large and extra-large screens.
97
98 ::::{grid} 2
99 :gutter: 1
100
101 :::{grid-item-card}
102 A
103 :::
104 :::{grid-item-card}
105 B
106 :::
107 ::::
108
109 ::::{grid} 2
110 :gutter: 3 3 4 5
111
112 :::{grid-item-card}
113 A
114 :::
115 :::{grid-item-card}
116 B
117 :::
118 ::::
119
120 `````{dropdown-syntax}
121
122 ````{tab-set-code}
123 ```{literalinclude} ./snippets/myst/grid-gutter.txt
124 :language: markdown
125 ```
126 ```{literalinclude} ./snippets/rst/grid-gutter.txt
127 :language: rst
128 ```
129 ````
130 `````
131
132 ## Item level column width
133
134 You can override the number of columns a single item takes up by using the `columns` option of the `grid-item` directive.
135 Given the total columns are 12, this means 12 would indicate a single item takes up the entire grid row, or 6 half.
136 Alternatively, use `auto` to automatically decide how many columns to use based on the item content.
137 Like for grid columns, you can either provide a single number or four for small, medium and large and extra-large screens.
138
139 ::::{grid} 2
140 :::{grid-item-card}
141 :columns: auto
142
143 A
144 :::
145 :::{grid-item-card}
146 :columns: 12 6 6 6
147
148 B
149 :::
150 :::{grid-item-card}
151 :columns: 12
152
153 C
154 :::
155 ::::
156
157 `````{dropdown-syntax}
158
159 ````{tab-set-code}
160 ```{literalinclude} ./snippets/myst/grid-card-columns.txt
161 :language: markdown
162 ```
163 ```{literalinclude} ./snippets/rst/grid-card-columns.txt
164 :language: rst
165 ```
166 ````
167 `````
168
169 ## Reversing the item order
170
171 Use the `grid` directive's `reverse` option to reverse the order of the items.
172 This can be useful if you want an item to be on the right side on large screens, but at the top on small screens.
173
174 ::::{grid} 1 1 2 2
175 :reverse:
176
177 :::{grid-item}
178 ```{image} ./images/ebp-logo.png
179 :width: 200px
180 :class: sd-m-auto
181 ```
182 :::
183
184 :::{grid-item-card}
185 Some text
186 :::
187
188 ::::
189
190 ## Nesting grids
191
192 Grids can be nested in other grids to create complex, adaptive layouts:
193
194 ::::::{grid} 1 1 2 2
195 :gutter: 1
196
197 :::::{grid-item}
198
199 ::::{grid} 1 1 1 1
200 :gutter: 1
201
202 :::{grid-item-card} Item 1.1
203
204 Multi-line
205
206 content
207
208 :::
209
210 :::{grid-item-card} Item 1.2
211
212 Content
213
214 :::
215
216 ::::
217
218 :::::
219
220 :::::{grid-item}
221
222 ::::{grid} 1 1 1 1
223 :gutter: 1
224
225 :::{grid-item-card} Item 2.1
226
227 Content
228
229 :::
230
231 :::{grid-item-card} Item 2.2
232
233 Content
234
235 :::
236
237 :::{grid-item-card} Item 2.3
238
239 Content
240
241 :::
242
243 ::::
244
245 :::::
246
247 ::::::
248
249 `````{dropdown-syntax}
250
251 ````{tab-set-code}
252 ```{literalinclude} ./snippets/myst/grid-nested.txt
253 :language: markdown
254 ```
255 ```{literalinclude} ./snippets/rst/grid-nested.txt
256 :language: rst
257 ```
258 ````
259 `````
260
261 See the [Bootstrap Grid system](https://getbootstrap.com/docs/5.0/layout/grid/) for further details.
262
263 ## `grid` options
264
265 gutter
266 : Spacing between items.
267 One or four integers (for "xs sm md lg") between 0 and 5.
268
269 margin
270 : Outer margin of grid.
271 One (all) or four (top bottom left right) values from: 0, 1, 2, 3, 4, 5, auto.
272
273 padding
274 : Inner padding of grid.
275 One (all) or four (top bottom left right) values from: 0, 1, 2, 3, 4, 5.
276
277 outline
278 : Create a border around the grid.
279
280 reverse
281 : Reverse the order of the grid items.
282
283 class-container
284 : Additional CSS classes for the grid container element.
285
286 class-row
287 : Additional CSS classes for the grid row element.
288
289 ## `grid-item` options
290
291 columns
292 : The number of columns (out of 12) a grid-item will take up.
293 One or four integers (for "xs sm md lg") between 1 and 12 (or `auto` to adapt to the content).
294
295 margin
296 : Outer margin of grid item.
297 One (all) or four (top bottom left right) values from: 0, 1, 2, 3, 4, 5, auto.
298
299 padding
300 : Inner padding of grid item.
301 One (all) or four (top bottom left right) values from: 0, 1, 2, 3, 4, 5.
302
303 child-direction
304 : Direction of children in the grid item: `column` (default) or `row`.
305
306 child-align
307 : Alignment of children, along the `child-direction`: `start` (default), `end`, `center`, `justify` or `spaced`.
308
309 outline
310 : Create a border around the grid item.
311
312 class
313 : Additional CSS classes for the grid item element.
314
315 ## `grid-item-card` options
316
317 columns
318 : The number of columns (out of 12) a grid-item will take up.
319 One or four integers (for "xs sm md lg") between 1 and 12 (or `auto` to adapt to the content).
320
321 margin
322 : Outer margin of grid item.
323 One (all) or four (top bottom left right) values from: 0, 1, 2, 3, 4, 5, auto.
324
325 padding
326 : Inner padding of grid item.
327 One (all) or four (top bottom left right) values from: 0, 1, 2, 3, 4, 5.
328
329 class-item
330 : Additional CSS classes for the grid item element.
331
332 Plus all options from [](cards:options).