Bootstrap Responsive Utilities
Bootstrap provides some helper classes to more quickly achieve mobile-friendly development. These use media queries combined with large, small, and medium devices to show or hide content on different devices.
These utilities should be used with caution to avoid creating completely different versions of the same site.Responsive utilities currently only apply to block and table toggling.
| onSelect | event | Extra Small Screens
Phones (<768px) | Small Screens
Tablets (>=768px) | Medium Screens
Desktops (>=992px) | Large Screens
Desktops (>=1200px)| onSelect | event | --- | --- | --- | --- | ---| onSelect | event | .visible-xs-* | Visible | Hidden | Hidden | Hidden| onSelect | event | .visible-sm-* | Hidden | Visible | Hidden | Hidden| onSelect | event | .visible-md-* | Hidden | Hidden | Visible | Hidden| onSelect | event | .visible-lg-* | Hidden | Hidden | Hidden | Visible| onSelect | event | .hidden-xs | Hidden | Visible | Visible | Visible| onSelect | event | .hidden-sm | Visible | Hidden | Visible | Visible| onSelect | event | .hidden-md | Visible | Visible | Hidden | Visible| onSelect | event | .hidden-lg | Visible | Visible | Visible | Hidden |
Starting from version v3.2.0, classes of the form .visible-- have three variants for each screen size, each targeting a different display property in CSS, listed as follows:
| Class Groups | CSS display |
|---|---|
| .visible-*-block | display: block; |
| .visible-*-inline | display: inline; |
| .visible-*-inline-block | display: inline-block; |
Therefore, taking extra small screens (xs) as an example, the available .visible-- classes are: .visible-xs-block, .visible-xs-inline, and .visible-xs-inline-block.
The .visible-xs, .visible-sm, .visible-md, and .visible-lg classes also exist. However, they are no longer recommended since v3.2.0. Except for the
Print Classes
The following table lists the print classes. Use these to toggle print content.
| class | Browser | Printer |
|---|---|---|
| .visible-print-block |
.visible-print-inline
.visible-print-inline-block | 隐藏 | 可见 |
| .hidden-print | Visible | Hidden |
Example
The following example demonstrates the use of the helper classes listed above. Resize the browser window or load the example on different devices to test the responsive utility classes.
Example
<div class="container" style=">padding: 40px;
"
<div class=">row visible-on
"
<div class=">col-xs-6 col-sm-3
"
style
=
"
background-color: #dedef8; box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;
"
<span class="hidden-xs">Extra Small
span
<span class="visible-xs">✔ Visible on extra small devices
span
div
<div class=">col-xs-6 col-sm-3
"
style
=
"
background-color: #dedef8; box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;
"
<span class="hidden-sm" Small span>
<span class="visible-sm">✔ Visible on small devices
span
div
<div class=">clearfix visible-xs
"
div
<div class=">col-xs-6 col-sm-3
"
style
=
"
background-color: #dedef8; box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;
"
<span class="hidden-md" Medium span>
<span class="visible-md">✔ Visible on medium devices
span
div
<div class=">col-xs-6 col-sm-3
"
style
=
"
background-color: #dedef8; box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;
"
<span class="hidden-lg" Large span>
<span class="visible-lg">✔ Visible on large devices
span
div
div
div
Try it »
The result is as follows:
Check mark (✔) indicates that the element is visible in the current viewport.