Kolomme
Leer hoe om kolomme te verander met 'n handvol opsies vir belyning, ordening en verrekening danksy ons flexbox-roosterstelsel. Sien boonop hoe om kolomklasse te gebruik om wydtes van nie-roosterelemente te bestuur.
Hoe hulle werk
-
Kolomme bou op die rooster se flexbox-argitektuur. Flexbox beteken dat ons opsies het om individuele kolomme te verander en groepe kolomme op ryvlak te wysig . Jy kies hoe kolomme groei, krimp of andersins verander.
-
Wanneer roosteruitlegte gebou word, gaan alle inhoud in kolomme. Die hiërargie van Bootstrap se rooster gaan van houer na ry na kolom na jou inhoud. By seldsame geleenthede kan jy inhoud en kolom kombineer, maar wees bewus daarvan dat daar onbedoelde gevolge kan wees.
-
Bootstrap bevat vooraf gedefinieerde klasse vir die skep van vinnige, responsiewe uitlegte. Met ses breekpunte en 'n dosyn kolomme by elke roostervlak, het ons dosyne klasse wat reeds vir jou gebou is om jou gewenste uitlegte te skep. Dit kan deur Sass gedeaktiveer word as jy wil.
Belyning
Gebruik flexbox-belyningshulpmiddels om kolomme vertikaal en horisontaal in lyn te bring.
Vertikale belyning
<div class="container">
<div class="row align-items-start">
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
</div>
<div class="row align-items-center">
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
</div>
<div class="row align-items-end">
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col align-self-start">
One of three columns
</div>
<div class="col align-self-center">
One of three columns
</div>
<div class="col align-self-end">
One of three columns
</div>
</div>
</div>
Horisontale belyning
<div class="container">
<div class="row justify-content-start">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
<div class="row justify-content-center">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
<div class="row justify-content-end">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
<div class="row justify-content-around">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
<div class="row justify-content-between">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
<div class="row justify-content-evenly">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
</div>
Kolom wikkel
As meer as 12 kolomme binne 'n enkele ry geplaas word, sal elke groep ekstra kolomme, as een eenheid, op 'n nuwe lyn toegedraai word.
Aangesien 9 + 4 = 13 > 12, word hierdie 4-kolom-wye div op 'n nuwe lyn toegedraai as een aaneenlopende eenheid.
Volgende kolomme gaan voort langs die nuwe lyn.
<div class="container">
<div class="row">
<div class="col-9">.col-9</div>
<div class="col-4">.col-4<br>Since 9 + 4 = 13 > 12, this 4-column-wide div gets wrapped onto a new line as one contiguous unit.</div>
<div class="col-6">.col-6<br>Subsequent columns continue along the new line.</div>
</div>
</div>
Kolombreuke
Om kolomme na 'n nuwe lyn in flexbox te breek, vereis 'n klein hack: voeg 'n element by width: 100%
waar jy jou kolomme ook al wil omvou na 'n nuwe lyn. Normaalweg word dit met veelvuldige s bewerkstellig .row
, maar nie elke implementeringsmetode kan hiervoor rekening hou nie.
<div class="container">
<div class="row">
<div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
<div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
<!-- Force next columns to break to new line -->
<div class="w-100"></div>
<div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
<div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
</div>
</div>
Jy kan ook hierdie breek by spesifieke breekpunte toepas met ons responsiewe vertoonhulpmiddels .
<div class="container">
<div class="row">
<div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
<div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
<!-- Force next columns to break to new line at md breakpoint and up -->
<div class="w-100 d-none d-md-block"></div>
<div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
<div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
</div>
</div>
Herrangskik
Bestel klasse
Use .order-
classes for controlling the visual order of your content. These classes are responsive, so you can set the order
by breakpoint (e.g., .order-1.order-md-2
). Includes support for 1
through 5
across all six grid tiers.
<div class="container">
<div class="row">
<div class="col">
First in DOM, no order applied
</div>
<div class="col order-5">
Second in DOM, with a larger order
</div>
<div class="col order-1">
Third in DOM, with an order of 1
</div>
</div>
</div>
There are also responsive .order-first
and .order-last
classes that change the order
of an element by applying order: -1
and order: 6
, respectively. These classes can also be intermixed with the numbered .order-*
classes as needed.
<div class="container">
<div class="row">
<div class="col order-last">
First in DOM, ordered last
</div>
<div class="col">
Second in DOM, unordered
</div>
<div class="col order-first">
Third in DOM, ordered first
</div>
</div>
</div>
Offsetting columns
You can offset grid columns in two ways: our responsive .offset-
grid classes and our margin utilities. Grid classes are sized to match columns while margins are more useful for quick layouts where the width of the offset is variable.
Offset classes
Move columns to the right using .offset-md-*
classes. These classes increase the left margin of a column by *
columns. For example, .offset-md-4
moves .col-md-4
over four columns.
<div class="container">
<div class="row">
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4 offset-md-4">.col-md-4 .offset-md-4</div>
</div>
<div class="row">
<div class="col-md-3 offset-md-3">.col-md-3 .offset-md-3</div>
<div class="col-md-3 offset-md-3">.col-md-3 .offset-md-3</div>
</div>
<div class="row">
<div class="col-md-6 offset-md-3">.col-md-6 .offset-md-3</div>
</div>
</div>
In addition to column clearing at responsive breakpoints, you may need to reset offsets. See this in action in the grid example.
<div class="container">
<div class="row">
<div class="col-sm-5 col-md-6">.col-sm-5 .col-md-6</div>
<div class="col-sm-5 offset-sm-2 col-md-6 offset-md-0">.col-sm-5 .offset-sm-2 .col-md-6 .offset-md-0</div>
</div>
<div class="row">
<div class="col-sm-6 col-md-5 col-lg-6">.col-sm-6 .col-md-5 .col-lg-6</div>
<div class="col-sm-6 col-md-5 offset-md-2 col-lg-6 offset-lg-0">.col-sm-6 .col-md-5 .offset-md-2 .col-lg-6 .offset-lg-0</div>
</div>
</div>
Margin utilities
With the move to flexbox in v4, you can use margin utilities like .me-auto
to force sibling columns away from one another.
<div class="container">
<div class="row">
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4 ms-auto">.col-md-4 .ms-auto</div>
</div>
<div class="row">
<div class="col-md-3 ms-md-auto">.col-md-3 .ms-md-auto</div>
<div class="col-md-3 ms-md-auto">.col-md-3 .ms-md-auto</div>
</div>
<div class="row">
<div class="col-auto me-auto">.col-auto .me-auto</div>
<div class="col-auto">.col-auto</div>
</div>
</div>
Standalone column classes
The .col-*
classes can also be used outside a .row
to give an element a specific width. Whenever column classes are used as non direct children of a row, the paddings are omitted.
<div class="col-3 bg-light p-3 border">
.col-3: width of 25%
</div>
<div class="col-sm-9 bg-light p-3 border">
.col-sm-9: width of 75% above sm breakpoint
</div>
The classes can be used together with utilities to create responsive floated images. Make sure to wrap the content in a .clearfix
wrapper to clear the float if the text is shorter.
A paragraph of placeholder text. We're using it here to show the use of the clearfix class. We're adding quite a few meaningless phrases here to demonstrate how the columns interact here with the floated image.
As you can see the paragraphs gracefully wrap around the floated image. Now imagine how this would look with some actual content in here, rather than just this boring placeholder text that goes on and on, but actually conveys no tangible information at. It simply takes up space and should not really be read.
En tog, hier is jy, nog steeds volhard om hierdie plekhouer-teks te lees, met die hoop op nog 'n paar insigte, of 'n verborge paaseier van inhoud. Miskien 'n grap. Ongelukkig is daar niks hiervan nie.
<div class="clearfix">
<img src="..." class="col-md-6 float-md-end mb-3 ms-md-3" alt="...">
<p>
A paragraph of placeholder text. We're using it here to show the use of the clearfix class. We're adding quite a few meaningless phrases here to demonstrate how the columns interact here with the floated image.
</p>
<p>
As you can see the paragraphs gracefully wrap around the floated image. Now imagine how this would look with some actual content in here, rather than just this boring placeholder text that goes on and on, but actually conveys no tangible information at. It simply takes up space and should not really be read.
</p>
<p>
And yet, here you are, still persevering in reading this placeholder text, hoping for some more insights, or some hidden easter egg of content. A joke, perhaps. Unfortunately, there's none of that here.
</p>
</div>