Display propertyDisplay属性
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.包括支持一些更常见的值,以及打印时控制显示的一些附加功能。
How it works作用原理
Change the value of the 使用响应显示实用程序类更改display
property with our responsive display utility classes. display
属性的值。We purposely support only a subset of all possible values for 我们特意只支持display
. display
所有可能值的子集。Classes can be combined for various effects as you need.可以根据需要组合类以获得各种效果。
Notation符号
Display utility classes that apply to all breakpoints, from 显示应用于所有断点(从xs
to xxl
, have no breakpoint abbreviation in them. xs
到xxl
)的实用程序类中没有断点缩写。This is because those classes are applied from 这是因为这些类是应用于min-width: 0;
and up, and thus are not bound by a media query. min-width: 0;
及以上;并且因此不受媒体查询的约束。The remaining breakpoints, however, do include a breakpoint abbreviation.然而,其余的断点确实包含断点缩写。
As such, the classes are named using the format:因此,类使用以下格式命名:
.d-{value}
for用于xs
xs
.d-{breakpoint}-{value}
for用于sm
,md
,lg
,xl
, andxxl
.sm
、md
、lg
、xl
和xxl
。
Where value is one of:其中value是以下值之一:
none
inline
inline-block
block
grid
table
table-cell
table-row
flex
inline-flex
The display values can be altered by changing the 可以通过更改$displays
variable and recompiling the SCSS.$displays
变量并重新编译SCSS来更改显示值。
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..d-lg-none
在lg
、xl
和xxl
屏幕上设置display: none;
。
Examples示例
<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>
<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>
Hiding elements隐藏元素
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.避免创建同一网站的完全不同版本,而是根据每个屏幕大小隐藏元素。
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..d-none
类或.d-{sm,md,lg,xl,xxl}-none
类中的一个来进行任何响应屏幕变化。
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 .d-xxl-none
will hide the element for all screen sizes except on medium and large devices..d-*-none
类与.d-*-*
类组合,例如.d-none .d-md-block .d-xl-none .d-xxl-none
将隐藏所有屏幕大小的元素,中型和大型设备除外。
.d-none |
|
.d-none .d-sm-block |
|
.d-sm-none .d-md-block |
|
.d-md-none .d-lg-block |
|
.d-lg-none .d-xl-block |
|
.d-xl-none .d-xxl-block |
|
.d-xxl-none |
|
.d-block |
|
.d-block .d-sm-none |
|
.d-none .d-sm-block .d-md-none |
|
.d-none .d-md-block .d-lg-none |
|
.d-none .d-lg-block .d-xl-none |
|
.d-none .d-xl-block .d-xxl-none |
|
.d-none .d-xxl-block |
<div class="d-lg-none">hide on lg and wider screens</div>
<div class="d-none d-lg-block">hide on screens smaller than lg</div>
Display in print打印时显示
Change the 使用打印显示实用程序类打印时,更改元素的display
value of elements when printing with our print display utility classes. display
值。Includes support for the same 包括支持与响应display
values as our responsive .d-*
utilities..d-*
实用程序相同的display
值。
.d-print-none
.d-print-inline
.d-print-inline-block
.d-print-block
.d-print-grid
.d-print-table
.d-print-table-row
.d-print-table-cell
.d-print-flex
.d-print-inline-flex
The print and display classes can be combined.打印类和显示类可以合并。
<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>
Sass
Utilities API实用程序API
Display utilities are declared in our utilities API in 显示实用程序在scss/_utilities.scss
. scss/_utilities.scss
中的实用程序API中声明。Learn how to use the utilities API.了解如何使用实用程序API。
"display": (
responsive: true,
print: true,
property: display,
class: d,
values: inline inline-block block grid table table-row table-cell flex inline-flex none
),