Bootstrap 4 tutorial

Utilities (4): Position / Screenreaders / Shadows / Sizing / Spacing

Position

Classes

Utility classes for setting CSS position property (see CSS reference for detail). There is no responsive class.

.position-(static|relative|absolute|fixed|sticky)

Fixed top / Fixed bottom / Sticky top

Options for fixing an element on top or bottom, and displaying on topmost with setting Z-index . These are typically used for navigation bars . See navbar demos bellow for detail.

Screenreaders

Summary

Example

An example using .sr-only-focusable .

Working example: set inside the bracket next ⇒ ( Skip to main content ).

Shadows

.shadow(-none|-sm|-lg)?

Examples

div.shadow-none

No shadow

div.shadow-sm

Small shadow

div.shadow

Regular shadow

div.shadow-lg

Larger shadow

Sizing

Utility classes for setting width and height.

Relative to the parent

Width example

.w-25
.w-50
.w-75
.w-100
.w-auto

Height example (in the parent with height:100px;)

.h-25
.h-50
.h-75
.h-100
.h-auto

Max-width example: img.mw-100 (fits to the parent width)

Max-height example: img.mh-100 in the parent with height:200px; (fits to the parent height)

Relative to the viewport

Examples

Min-width 100vw div.min-vw-100

Min-width 100vw

Min-height 100vw div.min-vh-100

Min-height 100vh

Width 100vw div.vw-100

Width 100vw

Height 100vw div.vh-100

Height 100vh

Spacing

Utility for setting margins and paddings.

Notation

.(m|p)(t|b|l|r|x|y)?-(0|1|2|3|4|5|n1|n2|n3|n4|n5|auto)

Example

Setting paddings to table cell td (pb-(0|1|2|3|4|5) (Bottom only) is omitted by no effect)

.p-(0|1|2|3|4|5) (All)

.p-0
.p-1
.p-2
.p-3
.p-4
.p-5

.px-(0|1|2|3|4|5) (Left+Right)

.px-0
.px-1
.px-2
.px-3
.px-4
.px-5

.py-(0|1|2|3|4|5) (Top+Bottom)

.py-0
.py-1
.py-2
.py-3
.py-4
.py-5

.pt-(0|1|2|3|4|5) (Top)

.pt-0
.pt-1
.pt-2
.pt-3
.pt-4
.pt-5

.pl-(0|1|2|3|4|5) (Left)

.pl-0
.pl-1
.pl-2
.pl-3
.pl-4
.pl-5

.pr-(0|1|2|3|4|5) (Right)

.pr-0
.pr-1
.pr-2
.pr-3
.pr-4
.pr-5

Horizontal centering

Use .mx-auto for horizontal centering of a fixed width element.

div.mx-auto + style="width: 20rem;"

Negative Margin

Negative margins are typically used for adjusting grid column gutters (see Gutters). The example below demonstrates responsive gutter adjustment as follows.

Custom column padding
Custom column padding