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