Bootstrap 4- hulpprogramma's
Bootstrap 4-hulpprogramma's
Bootstrap 4 heeft veel hulpprogramma-/helperklassen om snel elementen te stylen zonder CSS-code te gebruiken.
grenzen
Gebruik de border
klassen om randen aan een element toe te voegen of te verwijderen:
Voorbeeld
Voorbeeld
<span class="border"></span>
<span class="border border-0"></span>
<span class="border border-top-0"></span>
<span class="border border-right-0"></span>
<span
class="border border-bottom-0"></span>
<span class="border border-left-0"></span>
Rand kleur
Voeg een kleur toe aan de rand met een van de contextuele randkleurklassen:
Voorbeeld
Voorbeeld
<span class="border border-primary"></span>
<span class="border
border-secondary"></span>
<span class="border border-success"></span>
<span class="border border-danger"></span>
<span class="border
border-warning"></span>
<span class="border border-info"></span>
<span class="border border-light"></span>
<span class="border
border-dark"></span>
<span class="border border-white"></span>
Grensstraal
Voeg afgeronde hoeken toe aan een element met de rounded
klassen:
Voorbeeld
Voorbeeld
<span class="rounded-sm"></span>
<span class="rounded"></span>
<span class="rounded-lg"></span>
<span class="rounded-top"></span>
<span class="rounded-right"></span>
<span
class="rounded-bottom"></span>
<span class="rounded-left"></span>
<span class="rounded-circle"></span>
<span
class="rounded-0"></span>
Float en Clearfix
Zweef een element naar rechts met de .float-right
klasse of naar links met .float-left
, en verwijder floats met de .clearfix
klasse:
Voorbeeld
Voorbeeld
<div class="clearfix">
<span class="float-left">Float left</span>
<span
class="float-right">Float right</span>
</div>
Responsieve floats
Laat een element naar links of naar rechts zweven, afhankelijk van de schermbreedte, met de responsieve float-klassen ( .float-*-left|right
- waar * is sm
(>=576px), md
(>=768px), lg
(>=992px) of xl
(>=1200px)):
Voorbeeld
Voorbeeld
<div class="float-sm-right">Float right on small screens or wider</div><br>
<div class="float-md-right">Float right on medium screens or wider</div><br>
<div class="float-lg-right">Float right on large screens or wider</div><br>
<div class="float-xl-right">Float right on extra large screens or
wider</div><br>
<div class="float-none">Float none</div>
Uitlijnen in het midden
Centreer een element met de .mx-auto
klasse (voegt marge-links en marge-rechts toe: auto):
Voorbeeld
Voorbeeld
<div class="mx-auto
bg-warning" style="width:150px">Centered</div>
Breedte
Stel de breedte van een element in met de w-* klassen ( .w-25
, .w-50
, .w-75
, .w-100
, .mw-100
):
Voorbeeld
Voorbeeld
<div class="w-25 bg-warning">Width 25%</div>
<div class="w-50 bg-warning">Width
50%</div>
<div class="w-75 bg-warning">Width 75%</div>
<div
class="w-100 bg-warning">Width 100%</div>
<div class="mw-100 bg-warning">Max Width 100%</div>
Hoogte
Stel de hoogte van een element in met de h-* klassen ( .h-25
, .h-50
, .h-75
, .h-100
, .mh-100
):
Voorbeeld
Voorbeeld
<div style="height:200px;background-color:#ddd">
<div class="h-25 bg-warning">Height 25%</div>
<div class="h-50 bg-warning">Height
50%</div>
<div class="h-75 bg-warning">Height 75%</div>
<div
class="h-100 bg-warning">Height 100%</div>
<div class="mh-100 bg-warning"
style="height:500px">Max Height 100%</div>
</div>
Spatiëring
Bootstrap 4 heeft een breed scala aan responsieve marge- en opvulhulpklassen. Ze werken voor alle breekpunten: xs
(<=576px), sm
(>=576px), md
(>=768px), lg
(>=992px) of xl
(>=1200px)):
De klassen worden gebruikt in het formaat: {property}{sides}-{size}
voor xs
en {property}{sides}-{breakpoint}-{size}
voor sm
, md
, lg
, en xl
.
Waar eigendom is een van:
m
- setsmargin
p
- setspadding
Waar zijden een van is:
t
- setsmargin-top
ofpadding-top
b
- setsmargin-bottom
ofpadding-bottom
l
- setsmargin-left
ofpadding-left
r
- setsmargin-right
ofpadding-right
x
- stelt zowelpadding-left
enpadding-right
ofmargin-left
en inmargin-right
y
- stelt zowelpadding-top
enpadding-bottom
ofmargin-top
en inmargin-bottom
- blanco - stelt een
margin
ofpadding
in op alle 4 zijden van het element
Waar de maat een is van:
0
- setsmargin
ofpadding
to0
1
- setsmargin
ofpadding
to.25rem
(4px als de lettergrootte 16px is)2
- setsmargin
ofpadding
to.5rem
(8px als de lettergrootte 16px is)3
- setsmargin
ofpadding
to1rem
(16px als de lettergrootte 16px is)4
- setsmargin
ofpadding
to1.5rem
(24px als de lettergrootte 16px is)5
- setsmargin
ofpadding
to3rem
(48px als de lettergrootte 16px is)auto
- zetmargin
op automatisch
Let op: marges kunnen ook negatief zijn, door een "n" voor size toe te voegen :
n1
- wordt ingesteldmargin
op-.25rem
(-4px als de lettergrootte 16px is)n2
- wordt ingesteldmargin
op-.5rem
(-8px als de lettergrootte 16px is)n3
- wordt ingesteldmargin
op-1rem
(-16px als de lettergrootte 16px is)n4
- wordt ingesteldmargin
op-1.5rem
(-24px als de lettergrootte 16px is)n5
- wordt ingesteldmargin
op-3rem
(-48px als de lettergrootte 16px is)
Voorbeeld
Voorbeeld
<div class="pt-4 bg-warning">I only have a top padding (1.5rem =
24px)</div>
<div class="p-5 bg-success">I have a padding on all sides
(3rem = 48px)</div>
<div class="m-5 pb-5 bg-info">I have a margin on
all sides (3rem = 48px) and a bottom padding (3rem = 48px)</div>
Meer ruimtevoorbeelden
.m-# / m-*-# |
marge aan alle kanten | |
.mt-# / mt-*-# |
marge boven | |
.mb-# / mb-*-# |
marge onder | |
.ml-# / ml-*-# |
marge links | |
.mr-# / mr-*-# |
marge rechts | |
.mx-# / mx-*-# |
marge links en rechts | |
.my-# / my-*-# |
marge boven en onder | |
.p-# / p-*-# |
vulling aan alle kanten | |
.pt-# / pt-*-# |
vulling top | |
.pb-# / pb-*-# |
opvulling onderkant | |
.pl-# / pl-*-# |
opvulling links | |
.pr-# / pr-*-# |
opvulling rechts | |
.py-# / py-*-# |
opvulling boven en onder | |
.px-# / px-*-# |
opvulling links en rechts |
schaduwen
Gebruik de shadow-
klassen om schaduwen aan een element toe te voegen:
Voorbeeld
Voorbeeld
<div class="shadow-none p-4 mb-4 bg-light">No shadow</div>
<div
class="shadow-sm p-4 mb-4 bg-white">Small
shadow</div>
<div class="shadow p-4 mb-4 bg-white">Default
shadow</div>
<div class="shadow-lg p-4 mb-4 bg-white">Large
shadow</div>
Verticaal uitlijnen
Gebruik de align-
klassen om de uitlijning van elementen te wijzigen (werkt alleen op inline-, inline-block-, inline-table- en tabelcelelementen):
Voorbeeld
Voorbeeld
<span class="align-baseline">baseline</span>
<span
class="align-top">top</span>
<span class="align-middle">middle</span>
<span class="align-bottom">bottom</span>
<span
class="align-text-top">text-top</span>
<span
class="align-text-bottom">text-bottom</span>
Responsieve insluitingen
Maak responsieve insluitingen voor video's of diavoorstellingen op basis van de breedte van de ouder.
Voeg de .embed-responsive-item
toe aan alle ingesloten elementen (zoals <iframe> of <video>) in een bovenliggend element met .embed-responsive
en een beeldverhouding naar keuze:
Voorbeeld
Voorbeeld
<!-- 21:9 aspect ratio -->
<div class="embed-responsive
embed-responsive-21by9">
<iframe class="embed-responsive-item"
src="..."></iframe>
</div>
<!-- 16:9 aspect ratio -->
<div class="embed-responsive
embed-responsive-16by9">
<iframe class="embed-responsive-item"
src="..."></iframe>
</div>
<!-- 4:3 aspect ratio -->
<div class="embed-responsive
embed-responsive-4by3">
<iframe class="embed-responsive-item"
src="..."></iframe>
</div>
<!-- 1:1 aspect ratio -->
<div class="embed-responsive
embed-responsive-1by1">
<iframe class="embed-responsive-item"
src="..."></iframe>
</div>
Zichtbaarheid
Gebruik de klassen .visible
of .invisible
om de zichtbaarheid van elementen te regelen. Opmerking: deze klassen veranderen de CSS-weergavewaarde niet. Ze voegen alleen visibility:visible
of toe visibility:hidden
:
Voorbeeld
Voorbeeld
<div class="visible">I am visible</div>
<div class="invisible">I am
invisible</div>
Positie
Gebruik de .fixed-top
klasse om elk element vast te maken / bovenaan de pagina te blijven:
Voorbeeld
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
...
</nav>
Use the .fixed-bottom
class to make any element fixed/stay at
the bottom of the page:
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-bottom">
...
</nav>
Use the .sticky-top
class to make any element fixed/stay at
the top of the page when you scroll past it. Note:
This class does not work in IE11 and earlier (will treat it as position:relative
).
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark sticky-top">
...
</nav>
Close icon
Use the .close
class to style a close icon. This is often used for alerts and modals. Note that we use the ×
symbol to create the actual icon (a better looking
"x"). Also note that it floats right by default:
Example
Example
<button type="button" class="close">×</button>
Screenreaders
Use the .sr-only
class to hide an element on all devices, except screen readers:
Example
<span class="sr-only">I will be hidden on all screens except for screen
readers.</span>
Colors
As described in the Colors chapter, here is a list of all text and background color classes:
The classes for text colors are: .text-muted
,
.text-primary
, .text-success
, .text-info
,
.text-warning
, .text-danger
, .text-secondary
, .text-white
,
.text-dark
, .text-body
(default body color/often black) and .text-light
:
Example
This text is muted.
This text is important.
This text indicates success.
This text represents some information.
This text represents a warning.
This text represents danger.
Secondary text.
Dark grey text.
Body text.
Light grey text.
Contextual text classes can also be used on links, which will add a darker hover color:
Example
You can also add 50% opacity for black or white text with the .text-black-50
or .text-white-50
classes:
Example
Black text with 50% opacity on white background
White text with 50% opacity on black background
Background Colors
The classes for background colors are: .bg-primary
,
.bg-success
, .bg-info
, .bg-warning
, .bg-danger
, .bg-secondary
, .bg-dark
and .bg-light
.
Note that background colors do not set the text color, so in some cases you'll want to use them together with a .text-*
class.
Example
This text is important.
This text indicates success.
This text represents some information.
This text represents a warning.
This text represents danger.
Secondary background color.
Dark grey background color.
Light grey background color.
Typography/Text Classes
As described in the Typography chapter, here is a list of all typography/text classes:
Class | Description | Example |
---|---|---|
.display-* |
Display headings are used to stand out more than normal headings (larger font-size and lighter font-weight), and there are four classes to choose from: .display-1 , .display-2 , .display-3 , .display-4 |
|
.font-weight-bold |
Bold text | |
.font-weight-bolder |
Bolder bold text | |
.font-weight-normal |
Normal text | |
.font-weight-light |
Light weight text | |
.font-weight-lighter |
Lighter weight text | |
.font-italic |
Italic text | |
.lead |
Makes a paragraph stand out | |
.small |
Indicates smaller text (set to 85% of the size of the parent) | |
.text-break |
Prevents long text from breaking layout | |
.text-center |
Indicates center-aligned text | |
.text-decoration-none |
Removes the underline from a link | |
.text-left |
Indicates left-aligned text | |
.text-justify |
Indicates justified text | |
.text-monospace |
Monospaced text | |
.text-nowrap |
Indicates no wrap text | |
.text-lowercase |
Indicates lowercased text | |
.text-reset |
Resets the color of a text or a link (inherits the color from its parent) | |
.text-right |
Indicates right-aligned text | |
.text-uppercase |
Indicates uppercased text | |
.text-capitalize |
Indicates capitalized text | |
.initialism |
Displays the text inside an <abbr> element in a slightly smaller font size |
|
.list-unstyled |
Removes the default list-style and left margin on list items (works on both <ul> and <ol> ). This class only applies to immediate children list items (to remove the default list-style from any nested lists, apply this class to any nested lists as well) |
|
.list-inline |
Places all list items on a single line (used together with
.list-inline-item on each <li> elements) |
|
.pre-scrollable |
Makes a <pre> element scrollable |
Block Elements
To make an element into a block element, add the .d-block
class. Use any of the d-*-block
classes to control WHEN the element should be a block element on a specific screen width:
Example
Example
<span class="d-block bg-success">d-block</span>
<span class="d-sm-block
bg-success">d-sm-block</span>
<span class="d-md-block bg-success">d-md-block</span>
<span class="d-lg-block bg-success">d-lg-block</span>
<span
class="d-xl-block bg-success">d-xl-block</span>
Other Display Classes
Other display classes are also available:
Class | Description | Example |
---|---|---|
.d-none |
Hides an element | |
.d-*-none |
Hides an element on a specific screen size | |
.d-inline |
Makes an element inline | |
.d-*-inline |
Makes an element inline on a specific screen size | |
.d-inline-block |
Makes an element inline block | |
.d-*-inline-block |
Makes an element inline block on a specific screen size | |
.d-table |
Makes an element display as a table | |
.d-*-table |
Makes an element display as a table on a specific screen size | |
.d-table-cell |
Makes an element display as a table cell | |
.d-*-table-cell |
Makes an element display as a table cell on a specific screen size | |
.d-table-row |
Makes an element display as a table row | |
.d-*-table-row |
Makes an element display as a table row on a specific screen size | |
.d-flex |
Creates a flexbox container and transforms direct children into flex items | |
.d-*-flex |
Creates a flexbox container on a specific screen size | |
.d-inline-flex |
Creates an inline flexbox container | |
.d-*-inline-flex |
Creates an inline flexbox container on a specific screen size |
Flex
Use .flex-*
classes to control the layout with flexbox.
Read more about Bootstrap 4 Flex, in our next chapter.
Example
Horizontal:
Vertical: