|
| 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 | +:icon: code |
| 14 | +:color: light |
| 15 | +
|
| 16 | +````{tab-set-code} |
| 17 | +```{literalinclude} ./snippets/myst/div-basic.txt |
| 18 | +:language: markdown |
| 19 | +``` |
| 20 | +```{literalinclude} ./snippets/rst/div-basic.txt |
| 21 | +:language: rst |
| 22 | +``` |
| 23 | +```` |
| 24 | +````` |
| 25 | + |
| 26 | +If you find yourself using a class(es) often, consider openeing an issue to request a new role/directive or option! |
| 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 | +- Weight: |
| 38 | + - `sd-font-weight-light` |
| 39 | + - `sd-font-weight-lighter` |
| 40 | + - `sd-font-weight-normal` |
| 41 | + - `sd-font-weight-bold` |
| 42 | + - `sd-font-weight-bolder` |
| 43 | +- Style |
| 44 | + - `sd-font-italic` |
| 45 | + - `sd-text-decoration-none` |
| 46 | + - `sd-text-lowercase` |
| 47 | + - `sd-text-uppercase` |
| 48 | + - `sd-text-capitalize` |
| 49 | +- Wrapping |
| 50 | + - `sd-text-wrap` |
| 51 | + - `sd-text-nowrap` |
| 52 | + - `sd-text-truncate` (requires `display: inline-block` or `display: block`) |
| 53 | +- Color |
| 54 | + - `sd-text-{semantic color name}` (uses `--sd-color-{semantic color name}` CSS variable) |
| 55 | + - `sd-bg-text-{semantic color name}` (uses `--sd-color-{semantic color name}-text` CSS variable) |
| 56 | + |
| 57 | +## Display |
| 58 | + |
| 59 | +Define the layout of an element and its children (see [`display`](https://developer.mozilla.org/en-US/docs/Web/CSS/display)): |
| 60 | + |
| 61 | +- `sd-d-none` |
| 62 | +- `sd-d-inline` |
| 63 | +- `sd-d-inline-block` |
| 64 | +- `sd-d-block` |
| 65 | +- `sd-d-grid` |
| 66 | +- `sd-d-flex` |
| 67 | +- `sd-d-inline-flex` |
| 68 | + |
| 69 | +Variants are also available for screen-sizes (xs, sm, md, lg), e.g. `sd-d-sm-none`. |
| 70 | + |
| 71 | +Items within a flex box can also be aligned: |
| 72 | + |
| 73 | +- `sd-align-items-start` |
| 74 | +- `sd-align-items-end` |
| 75 | +- `sd-align-items-center` |
| 76 | + |
| 77 | +## Sizing |
| 78 | + |
| 79 | +Size objects width/height by percentage: |
| 80 | + |
| 81 | +- `sd-width-25`, `sd-height-25` |
| 82 | +- `sd-width-50`, `sd-height-50` |
| 83 | +- `sd-width-75`, `sd-height-75` |
| 84 | +- `sd-width-100`, `sd-height-100` |
| 85 | +- `sd-width-auto`, `sd-height-auto` |
| 86 | + |
| 87 | +## Spacing |
| 88 | + |
| 89 | +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). |
| 90 | + |
| 91 | +Spacing are defined on a scale of 0 to 5, for example `sd-px-1` or `sd-mt-5`. |
| 92 | + |
| 93 | +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}`. |
| 94 | + |
| 95 | +## Colors |
| 96 | + |
| 97 | +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. |
| 98 | + |
| 99 | +- `sd-bg-{name}` |
| 100 | +- `sd-bg-text-{name}` |
| 101 | +- `sd-text-{name}` |
| 102 | +- `sd-outline-{name}` |
| 103 | + |
| 104 | +Additional transparent colouring: |
| 105 | + |
| 106 | +- `sd-bg-transparent` |
| 107 | +- `sd-outline-transparent` |
| 108 | +- `sd-text-transparent` |
| 109 | + |
| 110 | +## Borders |
| 111 | + |
| 112 | +Borders can be applied to elements of thickness 0 to 5, for all are a specific side: |
| 113 | + |
| 114 | +- `sd-border-{thickness}` |
| 115 | +- `sd-border-top-{thickness}` |
| 116 | +- `sd-border-bottom-{thickness}` |
| 117 | +- `sd-border-right-{thickness}` |
| 118 | +- `sd-border-left-{thickness}` |
| 119 | + |
| 120 | +````{grid} 1 2 3 3 |
| 121 | +:gutter: 1 |
| 122 | +
|
| 123 | +```{grid-item-card} |
| 124 | +:shadow: none |
| 125 | +:class-card: sd-border-0 |
| 126 | +
|
| 127 | +`sd-border-0` |
| 128 | +``` |
| 129 | +```{grid-item-card} |
| 130 | +:shadow: none |
| 131 | +:class-card: sd-border-1 |
| 132 | +
|
| 133 | +`sd-border-1` |
| 134 | +``` |
| 135 | +```{grid-item-card} |
| 136 | +:shadow: none |
| 137 | +:class-card: sd-border-2 |
| 138 | +
|
| 139 | +`sd-border-2` |
| 140 | +``` |
| 141 | +```{grid-item-card} |
| 142 | +:shadow: none |
| 143 | +:class-card: sd-border-3 |
| 144 | +
|
| 145 | +`sd-border-3` |
| 146 | +``` |
| 147 | +```{grid-item-card} |
| 148 | +:shadow: none |
| 149 | +:class-card: sd-border-4 |
| 150 | +
|
| 151 | +`sd-border-4` |
| 152 | +``` |
| 153 | +```{grid-item-card} |
| 154 | +:shadow: none |
| 155 | +:class-card: sd-border-5 |
| 156 | +
|
| 157 | +`sd-border-5` |
| 158 | +``` |
| 159 | +```` |
| 160 | + |
| 161 | +Border can be rounded by different amounts using: |
| 162 | + |
| 163 | +- `sd-rounded-0` |
| 164 | +- `sd-rounded-1` |
| 165 | +- `sd-rounded-2` |
| 166 | +- `sd-rounded-3` |
| 167 | +- `sd-rounded-pill` |
| 168 | +- `sd-rounded-circle` |
| 169 | + |
| 170 | +````{grid} 1 2 3 3 |
| 171 | +:gutter: 1 |
| 172 | +
|
| 173 | +```{grid-item-card} |
| 174 | +:shadow: none |
| 175 | +:class-card: sd-rounded-0 |
| 176 | +
|
| 177 | +`sd-rounded-0` |
| 178 | +``` |
| 179 | +```{grid-item-card} |
| 180 | +:shadow: none |
| 181 | +:class-card: sd-rounded-1 |
| 182 | +
|
| 183 | +`sd-rounded-1` |
| 184 | +``` |
| 185 | +```{grid-item-card} |
| 186 | +:shadow: none |
| 187 | +:class-card: sd-rounded-2 |
| 188 | +
|
| 189 | +`sd-rounded-2` |
| 190 | +``` |
| 191 | +```{grid-item-card} |
| 192 | +:shadow: none |
| 193 | +:class-card: sd-rounded-3 |
| 194 | +
|
| 195 | +`sd-rounded-3` |
| 196 | +``` |
| 197 | +```{grid-item-card} |
| 198 | +:shadow: none |
| 199 | +:class-card: sd-rounded-pill |
| 200 | +
|
| 201 | +`sd-rounded-pill` |
| 202 | +``` |
| 203 | +```{grid-item-card} |
| 204 | +:shadow: none |
| 205 | +:class-card: sd-rounded-circle |
| 206 | +
|
| 207 | +`sd-rounded-circle` |
| 208 | +``` |
| 209 | +```` |
| 210 | + |
| 211 | +## Shadows |
| 212 | + |
| 213 | +Shadows can be applied to box elements (the color of the shadow is defined using `--sd-color-shadow` CSS variable): |
| 214 | + |
| 215 | +- `sd-shadow-none` |
| 216 | +- `sd-shadow-sm` |
| 217 | +- `sd-shadow-md` |
| 218 | +- `sd-shadow-lg` |
| 219 | + |
| 220 | +````{grid} 1 2 3 4 |
| 221 | +:gutter: 3 |
| 222 | +
|
| 223 | +```{grid-item-card} |
| 224 | +:shadow: none |
| 225 | +
|
| 226 | +`sd-shadow-none` |
| 227 | +``` |
| 228 | +```{grid-item-card} |
| 229 | +:shadow: sm |
| 230 | +
|
| 231 | +`sd-shadow-sm` |
| 232 | +``` |
| 233 | +```{grid-item-card} |
| 234 | +:shadow: md |
| 235 | +
|
| 236 | +`sd-shadow-md` |
| 237 | +``` |
| 238 | +```{grid-item-card} |
| 239 | +:shadow: lg |
| 240 | +
|
| 241 | +`sd-shadow-lg` |
| 242 | +``` |
| 243 | +```` |
| 244 | + |
| 245 | +## Avatars |
| 246 | + |
| 247 | +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)). |
| 248 | + |
| 249 | +These classes center an image, set their size and add a circular crop: |
| 250 | + |
| 251 | +- `sd-avatar-xs` |
| 252 | +- `sd-avatar-sm` |
| 253 | +- `sd-avatar-md` |
| 254 | +- `sd-avatar-lg` |
| 255 | +- `sd-avatar-xl` |
| 256 | + |
| 257 | +````{grid} 1 2 3 3 |
| 258 | +:gutter: 1 |
| 259 | +
|
| 260 | +```{grid-item-card} sd-avatar-xs |
| 261 | +<img src="images/ebp-logo.png" class="sd-avatar-xs sd-border-1"> |
| 262 | +``` |
| 263 | +```{grid-item-card} sd-avatar-sm |
| 264 | +<img src="images/ebp-logo.png" class="sd-avatar-sm sd-border-1"> |
| 265 | +``` |
| 266 | +```{grid-item-card} sd-avatar-md |
| 267 | +<img src="images/ebp-logo.png" class="sd-avatar-md sd-border-1"> |
| 268 | +``` |
| 269 | +```{grid-item-card} sd-avatar-lg |
| 270 | +<img src="images/ebp-logo.png" class="sd-avatar-lg sd-border-1"> |
| 271 | +``` |
| 272 | +```{grid-item-card} sd-avatar-xl |
| 273 | +<img src="images/ebp-logo.png" class="sd-avatar-xl sd-border-1"> |
| 274 | +``` |
| 275 | +```` |
0 commit comments