| 1 |
# CSS Classes |
| 2 |
|
| 3 |
For most roles/directive, it is preferentially recommended to use the available options to style components since, for example, this allows for better cross-output-format styling. |
| 4 |
|
| 5 |
But for custom cases, these roles/directives also provide `class` options for adding CSS classes directly to element, or you can directly use the `div` directive. |
| 6 |
All CSS classes that are part of sphinx-design are prefixed with `sd-`. |
| 7 |
|
| 8 |
:::{div} sd-text-center sd-font-italic sd-text-primary |
| 9 |
Some CSS styled text |
| 10 |
::: |
| 11 |
|
| 12 |
`````{dropdown-syntax} |
| 13 |
|
| 14 |
````{tab-set-code} |
| 15 |
```{literalinclude} ./snippets/myst/div-basic.txt |
| 16 |
:language: markdown |
| 17 |
``` |
| 18 |
```{literalinclude} ./snippets/rst/div-basic.txt |
| 19 |
:language: rst |
| 20 |
``` |
| 21 |
```` |
| 22 |
````` |
| 23 |
|
| 24 |
If you find yourself using a class(es) often, consider opening an issue to request a new role/directive or option! |
| 25 |
|
| 26 |
The `div` directive also has the `style` option, which allows you to add inline CSS styles, although it is not recommended to use this option for most cases. |
| 27 |
|
| 28 |
## Text |
| 29 |
|
| 30 |
Classes are available for styling and alignment: |
| 31 |
|
| 32 |
- Alignment: |
| 33 |
- `sd-text-justify` |
| 34 |
- `sd-text-left` |
| 35 |
- `sd-text-right` |
| 36 |
- `sd-text-center` |
| 37 |
- Size (size decreases from 1 to 6): |
| 38 |
- `sd-fs-1` |
| 39 |
- `sd-fs-2` |
| 40 |
- `sd-fs-3` |
| 41 |
- `sd-fs-4` |
| 42 |
- `sd-fs-5` |
| 43 |
- `sd-fs-6` |
| 44 |
- Weight: |
| 45 |
- `sd-font-weight-light` |
| 46 |
- `sd-font-weight-lighter` |
| 47 |
- `sd-font-weight-normal` |
| 48 |
- `sd-font-weight-bold` |
| 49 |
- `sd-font-weight-bolder` |
| 50 |
- Style |
| 51 |
- `sd-font-italic` |
| 52 |
- `sd-text-decoration-none` |
| 53 |
- `sd-text-lowercase` |
| 54 |
- `sd-text-uppercase` |
| 55 |
- `sd-text-capitalize` |
| 56 |
- Wrapping |
| 57 |
- `sd-text-wrap` |
| 58 |
- `sd-text-nowrap` |
| 59 |
- `sd-text-truncate` (requires `display: inline-block` or `display: block`) |
| 60 |
- Color |
| 61 |
- `sd-text-{semantic color name}` (uses `--sd-color-{semantic color name}` CSS variable) |
| 62 |
- `sd-bg-text-{semantic color name}` (uses `--sd-color-{semantic color name}-text` CSS variable) |
| 63 |
|
| 64 |
## Display |
| 65 |
|
| 66 |
Define the layout of an element and its children (see [`display`](https://developer.mozilla.org/en-US/docs/Web/CSS/display)): |
| 67 |
|
| 68 |
- `sd-d-none` |
| 69 |
- `sd-d-inline` |
| 70 |
- `sd-d-inline-block` |
| 71 |
- `sd-d-block` |
| 72 |
- `sd-d-grid` |
| 73 |
- `sd-d-flex-row` (align items horizontally) |
| 74 |
- `sd-d-flex-column` (align items vertically) |
| 75 |
- `sd-d-inline-flex` |
| 76 |
|
| 77 |
Variants are also available for screen-sizes (xs, sm, md, lg), e.g. `sd-d-sm-none`. |
| 78 |
|
| 79 |
Items within a flex box can also be aligned along the major axis or minor axis, dependant on the flex-direction. |
| 80 |
For example, using `sd-d-flex-column` and `sd-align-major-center` will center the items in the vertical direction. |
| 81 |
|
| 82 |
- `sd-align-major-start` |
| 83 |
- `sd-align-major-end` |
| 84 |
- `sd-align-major-center` |
| 85 |
- `sd-align-major-spaced` (spaced to fill the full axis) |
| 86 |
- `sd-align-major-justify` (spaced to fill the full axis, with the first/last item on the edges of the axis) |
| 87 |
|
| 88 |
- `sd-align-minor-start` |
| 89 |
- `sd-align-minor-end` |
| 90 |
- `sd-align-minor-center` |
| 91 |
|
| 92 |
For more information, see [this guide to flexbox](https://css-tricks.com/snippets/css/a-guide-to-flexbox/). |
| 93 |
|
| 94 |
## Sizing |
| 95 |
|
| 96 |
Size objects width/height by percentage: |
| 97 |
|
| 98 |
- `sd-width-25`, `sd-height-25` |
| 99 |
- `sd-width-50`, `sd-height-50` |
| 100 |
- `sd-width-75`, `sd-height-75` |
| 101 |
- `sd-width-100`, `sd-height-100` |
| 102 |
- `sd-width-auto`, `sd-height-auto` |
| 103 |
|
| 104 |
## Spacing |
| 105 |
|
| 106 |
Padding (`p`) and margins (`m`) can be controlled with these classes for; (`t`)op, (`r`)ight, (`b`)ottom, (`l`)eft, `x` (left and right), and `y` (top and bottom). |
| 107 |
|
| 108 |
Spacing are defined on a scale of 0 to 5, for example `sd-px-1` or `sd-mt-5`. |
| 109 |
|
| 110 |
Note, for grids the special gutter classes `sd-g-{screen-size}-{spacing}` are used to set margins, or for only `x`/`y`; `sd-gx-{screen-size}-{spacing}`. |
| 111 |
|
| 112 |
## Colors |
| 113 |
|
| 114 |
Colors can be set using [CSS variable](./css_variables.md), they are defined for the semantic color names: `primary`, `secondary`, `success`, `warning`, `danger`, `info`, `light`, `dark`, and `muted`, and specific colors `black` and `white`. |
| 115 |
|
| 116 |
- `sd-bg-{name}` |
| 117 |
- `sd-bg-text-{name}` |
| 118 |
- `sd-text-{name}` |
| 119 |
- `sd-outline-{name}` |
| 120 |
|
| 121 |
Additional transparent colouring: |
| 122 |
|
| 123 |
- `sd-bg-transparent` |
| 124 |
- `sd-outline-transparent` |
| 125 |
- `sd-text-transparent` |
| 126 |
|
| 127 |
## Borders |
| 128 |
|
| 129 |
Borders can be applied to elements of thickness 0 to 5, for all are a specific side: |
| 130 |
|
| 131 |
- `sd-border-{thickness}` |
| 132 |
- `sd-border-top-{thickness}` |
| 133 |
- `sd-border-bottom-{thickness}` |
| 134 |
- `sd-border-right-{thickness}` |
| 135 |
- `sd-border-left-{thickness}` |
| 136 |
|
| 137 |
````{grid} 1 2 3 3 |
| 138 |
:gutter: 1 |
| 139 |
|
| 140 |
```{grid-item-card} |
| 141 |
:shadow: none |
| 142 |
:class-card: sd-border-0 |
| 143 |
|
| 144 |
`sd-border-0` |
| 145 |
``` |
| 146 |
```{grid-item-card} |
| 147 |
:shadow: none |
| 148 |
:class-card: sd-border-1 |
| 149 |
|
| 150 |
`sd-border-1` |
| 151 |
``` |
| 152 |
```{grid-item-card} |
| 153 |
:shadow: none |
| 154 |
:class-card: sd-border-2 |
| 155 |
|
| 156 |
`sd-border-2` |
| 157 |
``` |
| 158 |
```{grid-item-card} |
| 159 |
:shadow: none |
| 160 |
:class-card: sd-border-3 |
| 161 |
|
| 162 |
`sd-border-3` |
| 163 |
``` |
| 164 |
```{grid-item-card} |
| 165 |
:shadow: none |
| 166 |
:class-card: sd-border-4 |
| 167 |
|
| 168 |
`sd-border-4` |
| 169 |
``` |
| 170 |
```{grid-item-card} |
| 171 |
:shadow: none |
| 172 |
:class-card: sd-border-5 |
| 173 |
|
| 174 |
`sd-border-5` |
| 175 |
``` |
| 176 |
```` |
| 177 |
|
| 178 |
Border can be rounded by different amounts using: |
| 179 |
|
| 180 |
- `sd-rounded-0` |
| 181 |
- `sd-rounded-1` |
| 182 |
- `sd-rounded-2` |
| 183 |
- `sd-rounded-3` |
| 184 |
- `sd-rounded-pill` |
| 185 |
- `sd-rounded-circle` |
| 186 |
|
| 187 |
````{grid} 1 2 3 3 |
| 188 |
:gutter: 1 |
| 189 |
|
| 190 |
```{grid-item-card} |
| 191 |
:shadow: none |
| 192 |
:class-card: sd-rounded-0 |
| 193 |
|
| 194 |
`sd-rounded-0` |
| 195 |
``` |
| 196 |
```{grid-item-card} |
| 197 |
:shadow: none |
| 198 |
:class-card: sd-rounded-1 |
| 199 |
|
| 200 |
`sd-rounded-1` |
| 201 |
``` |
| 202 |
```{grid-item-card} |
| 203 |
:shadow: none |
| 204 |
:class-card: sd-rounded-2 |
| 205 |
|
| 206 |
`sd-rounded-2` |
| 207 |
``` |
| 208 |
```{grid-item-card} |
| 209 |
:shadow: none |
| 210 |
:class-card: sd-rounded-3 |
| 211 |
|
| 212 |
`sd-rounded-3` |
| 213 |
``` |
| 214 |
```{grid-item-card} |
| 215 |
:shadow: none |
| 216 |
:class-card: sd-rounded-pill |
| 217 |
|
| 218 |
`sd-rounded-pill` |
| 219 |
``` |
| 220 |
```{grid-item-card} |
| 221 |
:shadow: none |
| 222 |
:class-card: sd-rounded-circle |
| 223 |
|
| 224 |
`sd-rounded-circle` |
| 225 |
``` |
| 226 |
```` |
| 227 |
|
| 228 |
## Shadows |
| 229 |
|
| 230 |
Shadows can be applied to box elements (the color of the shadow is defined using `--sd-color-shadow` CSS variable): |
| 231 |
|
| 232 |
- `sd-shadow-none` |
| 233 |
- `sd-shadow-sm` |
| 234 |
- `sd-shadow-md` |
| 235 |
- `sd-shadow-lg` |
| 236 |
|
| 237 |
````{grid} 1 2 3 4 |
| 238 |
:gutter: 3 |
| 239 |
|
| 240 |
```{grid-item-card} |
| 241 |
:shadow: none |
| 242 |
|
| 243 |
`sd-shadow-none` |
| 244 |
``` |
| 245 |
```{grid-item-card} |
| 246 |
:shadow: sm |
| 247 |
|
| 248 |
`sd-shadow-sm` |
| 249 |
``` |
| 250 |
```{grid-item-card} |
| 251 |
:shadow: md |
| 252 |
|
| 253 |
`sd-shadow-md` |
| 254 |
``` |
| 255 |
```{grid-item-card} |
| 256 |
:shadow: lg |
| 257 |
|
| 258 |
`sd-shadow-lg` |
| 259 |
``` |
| 260 |
```` |
| 261 |
|
| 262 |
## Avatars |
| 263 |
|
| 264 |
Avatars can represent a user or a brand,with a logo or branded graphic ([see Material Design imagery](https://material.io/design/communication/imagery.html#informational-imagery)). |
| 265 |
|
| 266 |
These classes center an image, set their size and add a circular crop: |
| 267 |
|
| 268 |
- `sd-avatar-xs` |
| 269 |
- `sd-avatar-sm` |
| 270 |
- `sd-avatar-md` |
| 271 |
- `sd-avatar-lg` |
| 272 |
- `sd-avatar-xl` |
| 273 |
- `sd-avatar-inherit` |
| 274 |
- `sd-avatar-initial` |
| 275 |
|
| 276 |
````{grid} 1 2 3 3 |
| 277 |
:gutter: 1 |
| 278 |
|
| 279 |
```{grid-item-card} sd-avatar-xs |
| 280 |
<img src="images/ebp-logo.png" class="sd-avatar-xs sd-border-1"> |
| 281 |
``` |
| 282 |
```{grid-item-card} sd-avatar-sm |
| 283 |
<img src="images/ebp-logo.png" class="sd-avatar-sm sd-border-1"> |
| 284 |
``` |
| 285 |
```{grid-item-card} sd-avatar-md |
| 286 |
<img src="images/ebp-logo.png" class="sd-avatar-md sd-border-1"> |
| 287 |
``` |
| 288 |
```{grid-item-card} sd-avatar-lg |
| 289 |
<img src="images/ebp-logo.png" class="sd-avatar-lg sd-border-1"> |
| 290 |
``` |
| 291 |
```{grid-item-card} sd-avatar-xl |
| 292 |
<img src="images/ebp-logo.png" class="sd-avatar-xl sd-border-1"> |
| 293 |
``` |
| 294 |
```` |
| 295 |
|
| 296 |
## Load Animations |
| 297 |
|
| 298 |
Add CSS animations when loading elements using the `sd-animate-{name}` classes: |
| 299 |
|
| 300 |
- `sd-animate-slide-from-left` |
| 301 |
- `sd-animate-slide-from-right` |
| 302 |
- `sd-animate-grow100` |
| 303 |
- `sd-animate-grow50` |
| 304 |
- `sd-animate-grow50-rot20` |
| 305 |
|
| 306 |
See [uxdesign.cc](https://uxdesign.cc/the-ultimate-guide-to-proper-use-of-animation-in-ux-10bd98614fa9) and [material.io](https://material.io/design/motion/understanding-motion.html#user-education) for good guides to animation. |