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
|
(sd-cards)=
# Cards
Cards contain content and actions about a single subject.
A card is a flexible and extensible content container,
it can be formatted with components including headers and footers, titles and images.
:::{card} Card Title
Card content
:::
See the [Material Design](https://material.io/components/cards) and [Bootstrap card](https://getbootstrap.com/docs/5.0/layout/grid/) descriptions for further details.
`````{dropdown-syntax}
````{tab-set-code}
```{literalinclude} ./snippets/myst/card-basic.txt
:language: markdown
```
```{literalinclude} ./snippets/rst/card-basic.txt
:language: rst
```
````
`````
All content before the first occurrence of three or more `^^^` is considered as a header,
and all content after the final occurrence of three or more `+++` is considered as a footer:
:::{card} Card Title
Header
^^^
Card content
+++
Footer
:::
`````{dropdown-syntax}
````{tab-set-code}
```{literalinclude} ./snippets/myst/card-head-foot.txt
:language: markdown
```
```{literalinclude} ./snippets/rst/card-head-foot.txt
:language: rst
```
````
`````
When using cards in grids (see [`grid-item-card`](./grids.md)) footers can be aligned.
::::{grid} 2
:::{grid-item-card} Card Title
Header
^^^
Card content
+++
Footer
:::
:::{grid-item-card} Card Title
Header
^^^
Longer
Card content
+++
Footer
:::
::::
## Card images
You can also add an image as the background of a card or at the top/bottom of the card, with the `img-background`, `img-top`, `img-bottom` options:
:::::{grid} 2 3 3 4
::::{grid-item}
:::{card} Title
:img-background: images/particle_background.jpg
:class-card: sd-text-black
:img-alt: your desired alt text
Text
:::
::::
::::{grid-item-card} Title
:img-top: images/particle_background.jpg
:img-alt: your desired alt text
Header
^^^
Content
+++
Footer
::::
::::{grid-item-card} Title
:img-bottom: images/particle_background.jpg
:img-alt: your desired alt text
Header
^^^
Content
+++
Footer
::::
:::::
`````{dropdown-syntax}
````{tab-set-code}
```{literalinclude} ./snippets/myst/card-images.txt
:language: markdown
```
```{literalinclude} ./snippets/rst/card-images.txt
:language: rst
```
````
`````
(cards-clickable)=
## Clickable cards
Using the `link` and `link-type` options, you can turn an entire card into a clickable link.
Try hovering over then clicking on the cards below:
:::{card} Clickable Card (external)
:link: https://example.com
:link-alt: example.com
The entire card can be clicked to navigate to `https://example.com`.
:::
:::{card} Clickable Card (internal)
:link: cards-clickable
:link-type: ref
The entire card can be clicked to navigate to the `cards-clickable` reference target.
:::
`````{dropdown-syntax}
````{tab-set-code}
```{literalinclude} ./snippets/myst/card-link.txt
:language: markdown
```
```{literalinclude} ./snippets/rst/card-link.txt
:language: rst
```
````
`````
The **external link** created above is equivalent to using `<https://example.com>`
(<https://example.com>),
or if the `link-alt` option is provided, `[alt text](https://example.com)`
([alt text](https://example.com)).
:::{tip}
Using URLs as link text makes it harder
for disabled people and for search engines to digest your web page,
so it's best to provide link text via the `link-alt` option.
:::
The **internal link** created above is equivalent to using `` {ref}`cards-clickable` ``
({ref}`cards-clickable`),
or if the `link-alt` option is provided, `` {ref}`alt text <cards-clickable>` ``
({ref}`alt text <cards-clickable>`).
:::{note}
You cannot add additional links to the clickable card, neither in the card
title nor in the card body. The entire card becomes a single link to the
destination you specify, which overrides any other links inside the card.
:::
## Aligning cards
You can use the `text-align` option to align the text in a card,
and also `auto` margins to align the cards horizontally.
:::{card} Align Center
:width: 75%
:margin: 0 2 auto auto
:text-align: center
Content
:::
:::{card} Align Right
:width: 50%
:margin: 0 2 auto 0
:text-align: right
Content
:::
:::{card} Align Left
:width: 50%
:margin: 0 2 0 auto
:text-align: left
Content
:::
(cards:carousel)=
## Card carousels
The `card-carousel` directive can be used to create a single row of fixed width, scrollable cards.
The argument should be a number between 1 and 12, to denote the number of cards to display.
When scrolling a carousel, the scroll will snap to the start of the nearest card:
::::{card-carousel} 2
:::{card} card 1
content
:::
:::{card} card 2
Longer
content
:::
:::{card} card 3
:::
:::{card} card 4
:::
:::{card} card 5
:::
:::{card} card 6
:::
::::
`````{dropdown-syntax}
````{tab-set-code}
```{literalinclude} ./snippets/myst/card-carousel.txt
:language: markdown
```
```{literalinclude} ./snippets/rst/card-carousel.txt
:language: rst
```
````
`````
(cards:options)=
## `card` options
width
: The width that the card should take up (in %): auto, 25%, 50%, 75%, 100%.
margin
: Outer margin of grid.
One (all) or four (top bottom left right) values from: 0, 1, 2, 3, 4, 5, auto.
text-align
: Default horizontal text alignment: left, right, center or justify
img-background
: A URI (relative file path or URL) to an image to be placed below the content.
img-top
: A URI (relative file path or URL) to an image to be placed above the content.
img-bottom
: A URI (relative file path or URL) to an image to be placed below the content.
img-alt
: Alternative text for the image (that will be used by screen-readers).
link
: Turn the entire card into a clickable link to an external/internal target.
link-type
: Type of link: `url` (default), `ref`, `doc`, `any`.
link-alt
: Alternative text for the link (that will be used by screen-readers).
shadow
: The size of the shadow below the card: `none`, `sm` (default), `md`, `lg`.
class-card
: Additional CSS classes for the card container element.
class-header
: Additional CSS classes for the header element.
class-body
: Additional CSS classes for the body element.
class-title
: Additional CSS classes for the title element.
class-footer
: Additional CSS classes for the footer element.
class-img-top
: Additional CSS classes for the top image (if present).
class-img-bottom
: Additional CSS classes for the bottom image (if present).
|