Faiga fa'apipi'i
Fa'aoga la matou telefoni feavea'i-muamua flexbox grid e fausia ai fa'ata'ita'iga o foliga ma lapopo'a uma fa'afetai i le koluma e sefululua, lima fa'aletonu tali fa'asaga, Sass fesuia'i ma fa'afefiloi, ma le tele o vasega na mua'i fa'avasegaina.
E fa'aogaina e le Bootstrap's grid system se fa'asologa o koneteina, laina, ma koluma e fa'atulaga ma fa'aoga mea. E fausia i le flexbox ma e tali atoatoa. O loʻo i lalo se faʻataʻitaʻiga ma se vaʻaiga loloto i le auala e tuʻufaʻatasia ai le faʻasologa.
E fou pe le masani ile flexbox? Faitau lenei CSS Tricks flexbox taiala mo talaaga, upu, taʻiala, ma faʻailoga snippets.
<div class="container">
<div class="row">
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
</div>
</div>
O le fa'ata'ita'iga o lo'o i luga e fa'atupuina ai ni koluma tutusa-lautele se tolu i luga o masini la'ititi, feololo, lapopo'a ma fa'aopoopo e fa'aoga ai a tatou vasega fa'avasega. O na koluma e totonugalemu i le itulau ma le matua .container
.
Fa'amavae i lalo, o le auala lenei e galue ai:
- O pusa e maua ai se auala e fa'atotonugalemu ma fa'alava fa'alava mea o lo'o i totonu o lau 'upega tafa'ilagi. Fa'aoga
.container
mo se lautele pika talisa po'o.container-fluid
mowidth: 100%
le va'aiga uma ma le tele o masini. - O laina o afifi mo koluma. O koluma ta'itasi e fa'ata'atia
padding
(ta'ua o le alavai) mo le fa'atonutonuina o le va i le va. Onapadding
fa'afeagai lea i luga o laina e le lelei pito. I lenei auala, o mea uma o loʻo i totonu o au koluma o loʻo faʻaogaina i lalo i le itu agavale. - I se fa'asologa o fa'asologa, e tatau ona tu'u mea i totonu o koluma ma na'o koluma e mafai ona avea ma fa'asologa vave o laina.
- Fa'afetai i le flexbox, o koluma fa'asologa e aunoa ma se fa'atonuina o le
width
a otometi lava ona fa'atulagaina pei o koluma tutusa lautele. Mo se fa'ata'ita'iga, e fa fa'ata'ita'iga o.col-sm
le a otometi lava ona 25% le lautele mai le va'aiga la'ititi ma luga. Va'ai le vaega o koluma fa'apipi'i-aunoa mo nisi fa'ata'ita'iga. - O vasega koluma e fa'ailoa mai ai le aofa'i o koluma e te mana'o e fa'aoga mai le 12 e mafai ile laina. O lea la, afai e te manaʻo i ni koluma tutusa-lautele se tolu, e mafai ona e faʻaogaina
.col-4
. - O koluma
width
s e fa'atulaga i pasene, o lea e masani ai ona su'esu'e ma lapopo'a e fa'atatau i le elemene matua. - O koluma e fa'ata'atia
padding
e fai ai alavai i le va o koluma ta'itasi, peita'i, e mafai ona e aveesemargin
mai laina mapadding
mai koluma i.no-gutters
luga o le.row
. - Ina ia fa'agasolo le fa'asologa, e lima ta'otoga fa'asologa, tasi mo vaega ta'itasi e tali mai ai : va'aiga uma (laiti fa'aopoopo), la'ititi, feololo, lapo'a, ma le lapopo'a.
- E fa'avae vaega vaeluaga i luga ole laititi ole lautele ole fa'asalalauga fesili, o lona uiga e fa'aoga ile tasi vaega malepe ma mea uma o lo'o i luga (fa'ata'ita'iga,
.col-sm-4
fa'aoga i masini la'ititi, feololo, lapoa, ma isi masini tetele, ae le o lexs
va'aiga muamua). - E mafai ona e fa'aogaina vasega fa'avasega (pei
.col-4
) po'o Sass mixins mo le fa'ailoga fa'atusa.
Ia nofouta i tapula'a ma pusi i luga o le flexbox , pei o le le mafai ona fa'aogaina nisi o elemene HTML e fai ma koneteina fe'avea'i .
A'o fa'aogaina e Bootstrap le em
s po'o rem
le s mo le fa'amalamalamaina o le tele o lapopo'a, px
e fa'aaogaina le s mo fa'asologa fa'asologa ma le lautele o atigipusa. E mafua ona o le lautele o le va'aiga o lo'o i pika ma e le suia i le tele o le vai .
Va'ai pe fa'afefea ona galue vaega o le Bootstrap grid system i le tele o masini ma se laulau fa'aoga.
Fa'aopoopo la'ititi <576px |
Laiti ≥576px |
Medium ≥768px |
Tele ≥992px |
Tele tele ≥1200px |
|
---|---|---|---|---|---|
Max ipu lautele lautele | Leai (taavale) | 540px | 720px | 960px | 1140px |
Ulua'i vasega | .col- |
.col-sm- |
.col-md- |
.col-lg- |
.col-xl- |
# o koluma | 12 | ||||
Laufanua lautele | 30px (15px i itu taʻitasi o se koluma) | ||||
Nestable | ioe | ||||
Fa'atonu koluma | ioe |
Fa'aoga vasega koluma fa'apitoa mo le fa'avasegaina o koluma e aunoa ma se vasega fa'anumera manino e pei o .col-sm-6
.
Mo se faʻataʻitaʻiga, e lua faʻasologa faʻasologa e faʻaoga i masini uma ma vaʻaiga, mai xs
i le xl
. Fa'aopoopo so'o se numera o vasega fa'aitiiti iunite mo va'aiga ta'itasi e te mana'omia ma o le a tutusa le lautele o koluma uma.
<div class="container">
<div class="row">
<div class="col">
1 of 2
</div>
<div class="col">
2 of 2
</div>
</div>
<div class="row">
<div class="col">
1 of 3
</div>
<div class="col">
2 of 3
</div>
<div class="col">
3 of 3
</div>
</div>
</div>
O koluma tutusa-lautele e mafai ona vaevaeina i ni laina se tele, ae sa i ai se Safari flexbox bug na taofia ai lenei mea mai le galue e aunoa ma se faʻamatalaga manino flex-basis
poʻo border
. O lo'o iai fo'i fofo mo su'esu'ega tuai, ae le tatau ona mana'omia pe a e fa'afou.
<div class="container">
<div class="row">
<div class="col">Column</div>
<div class="col">Column</div>
<div class="w-100"></div>
<div class="col">Column</div>
<div class="col">Column</div>
</div>
</div>
Fa'atonu-aunoa mo koluma flexbox grid o lona uiga e mafai fo'i ona e setiina le lautele o le koluma e tasi ma fa'asolo otometi le fa'avasegaina o koluma fa'atasi. E mafai ona e fa'aogaina vasega fa'avasega (e pei ona fa'aalia i lalo), fa'afefiloi fa'asologa, po'o le lautele o laina. Manatua o isi koluma o le a suia e tusa lava po o le a le lautele o le koluma ogatotonu.
<div class="container">
<div class="row">
<div class="col">
1 of 3
</div>
<div class="col-6">
2 of 3 (wider)
</div>
<div class="col">
3 of 3
</div>
</div>
<div class="row">
<div class="col">
1 of 3
</div>
<div class="col-5">
2 of 3 (wider)
</div>
<div class="col">
3 of 3
</div>
</div>
</div>
Fa'aoga col-{breakpoint}-auto
vasega e fa'atele koluma e fa'atatau i le lautele fa'anatura o latou anotusi.
<div class="container">
<div class="row justify-content-md-center">
<div class="col col-lg-2">
1 of 3
</div>
<div class="col-md-auto">
Variable width content
</div>
<div class="col col-lg-2">
3 of 3
</div>
</div>
<div class="row">
<div class="col">
1 of 3
</div>
<div class="col-md-auto">
Variable width content
</div>
<div class="col col-lg-2">
3 of 3
</div>
</div>
</div>
Fausia koluma tutusa-lautele e vaelua laina se tele e ala i le faʻaofiina o se .w-100
mea e te manaʻo e malepe ai koluma i se laina fou. Ia fa'agaoioi le malologa e ala i le fa'afefiloi .w-100
ma nisi fa'aoga fa'aaliga tali .
<div class="row">
<div class="col">col</div>
<div class="col">col</div>
<div class="w-100"></div>
<div class="col">col</div>
<div class="col">col</div>
</div>
O le fa'asologa o Bootstrap e aofia ai vaega e lima o vasega ua uma ona fa'avasegaina mo le fauina o fa'ata'ita'iga lavelave. Fa'apitoa le lapopoa o au koluma i luga o masini fa'aopoopo laiti, la'ititi, feololo, lapo'a, po'o masini tetele e tusa lava pe e te mana'o e fetaui.
Mo grids e tutusa mai le laʻititi o masini i le tele, faʻaaoga le .col
ma .col-*
vasega. Fa'ailoa se vasega faanumera pe ae mana'omia se koluma fa'apitoa; a leai, lagona le saoloto e pipii i .col
.
<div class="row">
<div class="col">col</div>
<div class="col">col</div>
<div class="col">col</div>
<div class="col">col</div>
</div>
<div class="row">
<div class="col-8">col-8</div>
<div class="col-4">col-4</div>
</div>
I le fa'aaogaina o se seti se tasi o .col-sm-*
vasega, e mafai ai ona e faia se faiga fa'avasega fa'avae e amata fa'aputu a'o le'i fa'ata'atia i le pito la'ititi ( sm
).
<div class="row">
<div class="col-sm-8">col-sm-8</div>
<div class="col-sm-4">col-sm-4</div>
</div>
<div class="row">
<div class="col-sm">col-sm</div>
<div class="col-sm">col-sm</div>
<div class="col-sm">col-sm</div>
</div>
E te le mana'o e fa'aputu na'o lau koluma i ni vaega fa'asologa? Fa'aoga se tu'ufa'atasiga o vasega eseese mo vaega ta'itasi pe a mana'omia. Va'ai le fa'ata'ita'iga o lo'o i lalo mo se manatu sili atu pe fa'apefea ona fa'aoga uma.
<!-- Stack the columns on mobile by making one full-width and the other half-width -->
<div class="row">
<div class="col-12 col-md-8">.col-12 .col-md-8</div>
<div class="col-6 col-md-4">.col-6 .col-md-4</div>
</div>
<!-- Columns start at 50% wide on mobile and bump up to 33.3% wide on desktop -->
<div class="row">
<div class="col-6 col-md-4">.col-6 .col-md-4</div>
<div class="col-6 col-md-4">.col-6 .col-md-4</div>
<div class="col-6 col-md-4">.col-6 .col-md-4</div>
</div>
<!-- Columns are always 50% wide, on mobile and desktop -->
<div class="row">
<div class="col-6">.col-6</div>
<div class="col-6">.col-6</div>
</div>
Fa'aoga mea fa'aoga fa'aoga flexbox e fa'aoga ai koluma i luga ma fa'alava.
<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>
<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>
O alavai i le va o koluma i totonu oa tatou vasega fa'ata'oto e mafai ona aveese i le .no-gutters
. E aveese ai le leaga margin
s mai .row
ma le faalava padding
mai koluma tamaiti uma.
O le fa'ailoga puna lea mo le faia o nei sitaili. Manatua o le fa'asili o koluma e fa'atatau i na'o ulua'i koluma a tamaiti ma e fa'atatau i le filifilia o uiga . E ui o lenei mea e maua ai se tagata filifilia sili atu, o le padding koluma e mafai lava ona faʻapipiʻiina i mea faʻaoga avanoa .
Manaomia se mamanu pito-i-pito? Tuu le matua .container
pe .container-fluid
.
I le fa'ata'ita'iga, o lona uiga fa'apea. Manatua e mafai ona e faʻaauau pea ona faʻaogaina lenei mea ma isi vasega faʻasologa uma ua uma ona faʻatulagaina (e aofia ai le lautele o koluma, vaega tali, toe faʻatonu, ma isi mea).
<div class="row no-gutters">
<div class="col-12 col-sm-6 col-md-8">.col-12 .col-sm-6 .col-md-8</div>
<div class="col-6 col-md-4">.col-6 .col-md-4</div>
</div>
Afai e sili atu i le 12 koluma e tu'u i totonu o le laina e tasi, o vaega ta'itasi o isi koluma o le a, e tasi le iunite, afifi i se laina fou.
Talu mai le 9 + 4 = 13 > 12, o le vaega lea e 4-koluma-lautele e afifi i luga o se laina fou o se tasi o iunite soso'o.
O koluma mulimuli ane e fa'aauau i luga o le laina fou.
<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>
O le talepeina o koluma i se laina fou i le flexbox e manaʻomia ai se tamai hack: faʻaopoopo se elemene i width: 100%
soʻo se mea e te manaʻo e afifi ai au koluma i se laina fou. E masani lava e ausia lenei mea i le tele o .row
s, ae le o metotia faʻatinoga uma e mafai ona faʻamaonia mo lenei mea.
<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>
E mafai fo'i ona e fa'aogaina lenei malologa i nofoaga fa'apitoa fa'atasi ma a matou fa'aoga fa'aaliga tali .
<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>
Fa'aoga .order-
vasega mo le fa'atonutonuina o le fa'atonuga va'aia o au mea. O nei vasega e tali mai, o lea e mafai ai ona e setiina le order
mea e momotu ai (faataitaiga, .order-1.order-md-2
). E aofia ai le lagolago 1
i 12
vaega uma e lima.
<div class="container">
<div class="row">
<div class="col">
First, but unordered
</div>
<div class="col order-12">
Second, but last
</div>
<div class="col order-1">
Third, but first
</div>
</div>
</div>
E i ai fo'i tali .order-first
ma .order-last
vasega e suia ai le order
elemene e ala i le fa'aogaina order: -1
ma le order: 13
( order: $columns + 1
), i le faasologa. O nei vasega e mafai fo'i ona fa'afefiloi ma .order-*
vasega fa'anumera pe a mana'omia.
<div class="container">
<div class="row">
<div class="col order-last">
First, but last
</div>
<div class="col">
Second, but unordered
</div>
<div class="col order-first">
Third, but first
</div>
</div>
</div>
E mafai ona e fa'asili koluma fa'asologa i ni auala se lua: matou .offset-
vasega fa'avasega tali ma a matou mea fa'aoga pito i tua . O vasega fa'ava'a e fa'atutusa e fa'afetaui koluma a'o pito e sili atu ona aoga mo fa'ata'ita'iga vave e fesuia'i ai le lautele o le offset.
Fa'asolo koluma i le itu taumatau e fa'aoga ai .offset-md-*
vasega. O nei vasega e fa'ateleina le pito agavale o se koluma i *
koluma. Mo se fa'ata'ita'iga, .offset-md-4
fa'agaoioi .col-md-4
luga o koluma e fa.
<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>
I le faaopoopo atu i le kiliaina o koluma i nofoaga malolo tali, atonu e te manaʻomia le toe setiina o faʻamau. Va'ai i le fa'atinoga i le fa'ata'ita'iga fa'asologa .
<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>
Faatasi ai ma le siitia atu i le flexbox i le v4, e mafai ona e faʻaogaina mea faʻaoga faʻapitoa e pei .mr-auto
o le faʻamalosi o nai koluma mai le isi.
<div class="row">
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4 ml-auto">.col-md-4 .ml-auto</div>
</div>
<div class="row">
<div class="col-md-3 ml-md-auto">.col-md-3 .ml-md-auto</div>
<div class="col-md-3 ml-md-auto">.col-md-3 .ml-md-auto</div>
</div>
<div class="row">
<div class="col-auto mr-auto">.col-auto .mr-auto</div>
<div class="col-auto">.col-auto</div>
</div>
Ina ia fa'aputu au mea i le fa'asologa fa'aletonu, fa'aopoopo se seti fou .row
ma se seti o .col-sm-*
koluma i totonu ole .col-sm-*
koluma o iai. O laina fa'aputu e tatau ona aofia ai se seti o koluma e fa'aopoopo i le 12 pe itiiti ifo (e le mana'omia lou fa'aogaina uma o koluma e 12 o lo'o avanoa).
<div class="row">
<div class="col-sm-9">
Level 1: .col-sm-9
<div class="row">
<div class="col-8 col-sm-6">
Level 2: .col-8 .col-sm-6
</div>
<div class="col-4 col-sm-6">
Level 2: .col-4 .col-sm-6
</div>
</div>
</div>
</div>
A fa'aogaina faila Sass fa'apogai a Bootstrap, o lo'o ia te oe le filifiliga e fa'aoga ai suiga ma fa'afefiloi Sass e fatu ai fa'asologa o tu ma aga, fa'asinomaga, ma fa'asologa o itulau. O a matou vasega fa'avasegaina muamua e fa'aogaina nei lava fesuiaiga ma fa'afefiloi e tu'uina atu ai se vaega atoa o vasega sauni e fa'aoga mo fa'asologa vave tali.
Fuafuaga ma faafanua e fuafua ai le numera o koluma, le lautele o le alavai, ma le vaega o fesili a le aufaasālalau lea e amata ai koluma faaopeopea. Matou te fa'aogaina nei mea e fa'atupuina ai vasega fa'asologa o lo'o fa'amauina i luga, fa'apea fo'i ma fa'afefiloi masani o lo'o lisi atu i lalo.
Fa'afefiloi e fa'aoga fa'atasi ma le fa'asologa o fesuiaiga e fa'atupu ai semantic CSS mo koluma fa'asologa ta'itasi.
E mafai ona e fesuia'i suiga i au lava tulaga fa'ale-aganu'u, pe na'o le fa'aogaina o mea fa'afefiloi ma latou tau fa'aletonu. O se fa'ata'ita'iga lea o le fa'aogaina o tulaga fa'aletonu e fai ai se fa'asologa o koluma e lua ma se va i le va.
<div class="example-container">
<div class="example-row">
<div class="example-content-main">Main content</div>
<div class="example-content-secondary">Secondary content</div>
</div>
</div>
I le fa'aogaina o la matou fa'asologa Sass fesuiaiga ma fa'afanua, e mafai ona fa'avasega atoatoa vasega fa'avasega. Suia le numera o vaega, le tele o fesili a le aufaasālalau, ma le lautele o koneteina—ona toe tuufaatasia lea.
Ole numera o koluma fa'asologa e mafai ona suia e ala i fesuiaiga Sass. $grid-columns
e fa'aaogaina e fa'atupu ai le lautele (i le pasene) o koluma ta'itasi a'o $grid-gutter-width
fa'ataga le vaeluaga fa'apitoa e vaelua tutusa i luga padding-left
ma padding-right
mo alavai o koluma.
O le aga'i atu i tua atu o koluma lava latou, e mafai fo'i ona e fa'avasegaina le numera o fa'asologa fa'asologa. Afai e te mana'o na'o le fa laina fa'asologa, e te fa'afouina le $grid-breakpoints
ma $container-max-widths
i se mea fa'apenei:
A fai so'o se suiga i le Sass fesuia'i po'o fa'afanua, e tatau ona e fa'asaoina au suiga ma toe fa'aopoopo. O le faia o lea mea o le a maua ai se seti fou o vasega fa'avasega fa'asologa mo le lautele o koluma, fa'asili, ma le fa'atonuga. O le a fa'afouina fo'i mea faigaluega fa'aalia e tali atu e fa'aoga ai fa'aputuga masani. Ia mautinoa e seti fa'asologa fa'atatau ile px
(e le rem
, em
, po'o le %
).