|
| 1 | +# Display |
| 2 | + |
| 3 | +Responsive display utilities for controlling element visibility and layout behavior across breakpoints. Built on CSS [display](https://developer.mozilla.org/en-US/docs/Web/CSS/display) property with mobile-first responsive design and optimized for modern development workflows. |
| 4 | + |
| 5 | +## How it works |
| 6 | + |
| 7 | +Change the value of the display property with our responsive display utility classes. We purposely support only a subset of all possible values for display. Classes can be combined for various effects as you need. |
| 8 | + |
| 9 | +## Notation |
| 10 | + |
| 11 | +Display utility classes that apply to all breakpoints, from `xs` to `xxl`, have no breakpoint abbreviation in them. This is because those classes are applied from `min-width: 0;` and up, and thus are not bound by a media query. The remaining breakpoints, however, do include a breakpoint abbreviation. |
| 12 | + |
| 13 | +As such, the classes are named using the format: |
| 14 | + |
| 15 | +- `.d-{value}` for `xs` |
| 16 | +- `.d-{breakpoint}-{value}` for `sm`, `md`, `lg`, `xl`, and `xxl`. |
| 17 | + |
| 18 | +Supported display values: |
| 19 | + |
| 20 | +| Class Suffix | CSS Property | Use Case | |
| 21 | +|--------------|--------------|-----------| |
| 22 | +| `none` | `display: none` | Hide elements completely | |
| 23 | +| `block` | `display: block` | Block-level elements | |
| 24 | +| `inline` | `display: inline` | Inline elements | |
| 25 | +| `inline-block` | `display: inline-block` | Inline with block properties | |
| 26 | +| `flex` | `display: flex` | Flexbox containers | |
| 27 | +| `inline-flex` | `display: inline-flex` | Inline flexbox containers | |
| 28 | +| `grid` | `display: grid` | CSS Grid containers | |
| 29 | +| `inline-grid` | `display: inline-grid` | Inline grid containers | |
| 30 | +| `table` | `display: table` | Table layout | |
| 31 | +| `table-row` | `display: table-row` | Table row elements | |
| 32 | +| `table-cell` | `display: table-cell` | Table cell elements | |
| 33 | + |
| 34 | +The media queries affect screen widths with the given breakpoint or larger. For example, `.d-lg-none` sets `display: none;` on `lg`, `xl`, and `xxl` screens. |
| 35 | + |
| 36 | +## Hiding elements |
| 37 | + |
| 38 | +For faster mobile-friendly development, use responsive display classes for showing and hiding elements by device. Avoid creating entirely different versions of the same site, instead hide elements responsively for each screen size. |
| 39 | + |
| 40 | +To hide elements simply use the `.d-none` class or one of the `.d-{sm,md,lg,xl,xxl}-none` classes for any responsive screen variation. |
| 41 | + |
| 42 | +To show an element only on a given interval of screen sizes you can combine one `.d-*-none` class with a `.d-*-*` class, for example `.d-none` `.d-md-block` `.d-xl-none` will hide the element for all screen sizes except on medium and large devices. |
| 43 | + |
| 44 | +| Screen size | Class | |
| 45 | +| ----------- | ----- | |
| 46 | +| Hidden on all | `.d-none` | |
| 47 | +| Hidden only on xs | `.d-none` `.d-sm-block` | |
| 48 | +| Hidden only on sm | `.d-sm-none` `.d-md-block` | |
| 49 | +| Hidden only on md | `.d-md-none` `.d-lg-block` | |
| 50 | +| Hidden only on lg | `.d-lg-none` `.d-xl-block` | |
| 51 | +| Hidden only on xl | `.d-xl-none` `.d-xxl-block` | |
| 52 | +| Hidden only on xxl | `.d-xxl-none` | |
| 53 | +| Visible on all | `.d-block` | |
| 54 | +| Visible only on xs | `.d-block` `.d-sm-none` | |
| 55 | +| Visible only on sm | `.d-none` `.d-sm-block` `.d-md-none` | |
| 56 | +| Visible only on md | `.d-none` `.d-md-block` `.d-lg-none` | |
| 57 | +| Visible only on lg | `.d-none` `.d-lg-block` `.d-xl-none` | |
| 58 | +| Visible only on xl | `.d-none` `.d-xl-block` `.d-xxl-none` | |
| 59 | +| Visible only on xxl | `.d-none` `.d-xxl-block` | |
| 60 | + |
| 61 | +```html |
| 62 | +<div class="d-lg-none">hide on lg and wider screens</div> |
| 63 | +<div class="d-none d-lg-block">hide on screens smaller than lg</div> |
| 64 | +``` |
| 65 | + |
| 66 | +## Display in print |
| 67 | + |
| 68 | +Optimize layouts for print media using dedicated print utilities: |
| 69 | + |
| 70 | +- `.d-print-none` |
| 71 | +- `.d-print-inline` |
| 72 | +- `.d-print-inline-block` |
| 73 | +- `.d-print-block` |
| 74 | +- `.d-print-grid` |
| 75 | +- `.d-print-table` |
| 76 | +- `.d-print-table-row` |
| 77 | +- `.d-print-table-cell` |
| 78 | +- `.d-print-flex` |
| 79 | +- `.d-print-inline-flex` |
| 80 | + |
| 81 | +The print and display classes can be combined. |
| 82 | + |
| 83 | +## Examples |
| 84 | + |
| 85 | +<si-docs-component example="display/display" height="300"></si-docs-component> |
0 commit comments