display.md 4.1 KB
Newer Older
1
2
3
---
layout: docs
title: Display property
4
description: Quickly and responsively toggle the display value of components and more with our display utilities. Includes support for some of the more common values, as well as some extras for controlling display when printing.
5
group: utilities
6
toc: true
7
8
---

Andrew Murphy's avatar
Andrew Murphy committed
9
## How it works
10

Andrew Murphy's avatar
Andrew Murphy committed
11
Change the value of the [`display` property](https://developer.mozilla.org/en-US/docs/Web/CSS/display) 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.
12

13
14
## Notation

Andrew Murphy's avatar
Andrew Murphy committed
15
Display utility classes that apply to all [breakpoints]({{ site.baseurl }}/docs/{{ site.docs_version }}/layout/overview/#responsive-breakpoints), from `xs` to `xl`, 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.
Andrew Murphy's avatar
Andrew Murphy committed
16
17

As such, the classes are named using the format:
Mark Otto's avatar
Mark Otto committed
18

Andrew Murphy's avatar
Andrew Murphy committed
19
20
* `.d-{value}` for `xs`
* `.d-{breakpoint}-{value}` for `sm`, `md`, `lg`, and `xl`.
21

22
Where *value* is one of:
23
24
25
26
27
28
29

* `none`
* `inline`
* `inline-block`
* `block`
* `table`
* `table-cell`
30
* `table-row`
31
32
33
* `flex`
* `inline-flex`

34
35
The display values can be altered by changing the `$displays` variable and recompiling the SCSS.

XhmikosR's avatar
XhmikosR committed
36
The media queries affect screen widths with the given breakpoint *or larger*. For example, `.d-lg-none` sets `display: none;` on both `lg` and `xl` screens.
37
38

## Examples
39

m5o's avatar
m5o committed
40
{% capture example %}
41
42
<div class="d-inline p-2 bg-primary text-white">d-inline</div>
<div class="d-inline p-2 bg-dark text-white">d-inline</div>
m5o's avatar
m5o committed
43
44
{% endcapture %}
{% include example.html content=example %}
45

m5o's avatar
m5o committed
46
{% capture example %}
47
48
<span class="d-block p-2 bg-primary text-white">d-block</span>
<span class="d-block p-2 bg-dark text-white">d-block</span>
m5o's avatar
m5o committed
49
50
{% endcapture %}
{% include example.html content=example %}
51

52
## Hiding elements
53

54
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.
55

56
57
To hide elements simply use the `.d-none` class or one of the `.d-{sm,md,lg,xl}-none` classes for any responsive screen variation.

Jos Maissan's avatar
Jos Maissan committed
58
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.
59
60
61

| Screen Size        | Class |
| ---                | --- |
Andrew Murphy's avatar
Andrew Murphy committed
62
63
64
65
66
67
68
69
70
71
72
73
| Hidden on all      | `.d-none` |
| Hidden only on xs  | `.d-none .d-sm-block` |
| Hidden only on sm  | `.d-sm-none .d-md-block` |
| Hidden only on md  | `.d-md-none .d-lg-block` |
| Hidden only on lg  | `.d-lg-none .d-xl-block` |
| Hidden only on xl  | `.d-xl-none` |
| Visible on all     | `.d-block` |
| Visible only on xs | `.d-block .d-sm-none` |
| Visible only on sm | `.d-none .d-sm-block .d-md-none` |
| Visible only on md | `.d-none .d-md-block .d-lg-none` |
| Visible only on lg | `.d-none .d-lg-block .d-xl-none` |
| Visible only on xl | `.d-none .d-xl-block` |
74

m5o's avatar
m5o committed
75
{% capture example %}
76
<div class="d-lg-none">hide on lg and wider screens</div>
77
<div class="d-none d-lg-block">hide on screens smaller than lg</div>
m5o's avatar
m5o committed
78
79
{% endcapture %}
{% include example.html content=example %}
80

81
82
## Display in print

83
84
85
86
87
88
89
90
91
92
93
Change the `display` value of elements when printing with our print display utility classes. Includes support for the same `display` values as our responsive `.d-*` utilities.

- `.d-print-none`
- `.d-print-inline`
- `.d-print-inline-block`
- `.d-print-block`
- `.d-print-table`
- `.d-print-table-row`
- `.d-print-table-cell`
- `.d-print-flex`
- `.d-print-inline-flex`
94
95
96

The print and display classes can be combined.

m5o's avatar
m5o committed
97
{% capture example %}
Andrew Murphy's avatar
Andrew Murphy committed
98
99
100
<div class="d-print-none">Screen Only (Hide on print only)</div>
<div class="d-none d-print-block">Print Only (Hide on screen only)</div>
<div class="d-none d-lg-block d-print-block">Hide up to large on screen, but always show on print</div>
m5o's avatar
m5o committed
101
102
{% endcapture %}
{% include example.html content=example %}