Grid system hmanga siam a ni
Kan mobile-first flexbox grid chak tak hmangin column sawm leh pahnih system, default responsive tier panga, Sass variable leh mixin, leh class ruat lawk tam tak avangin layout chi hrang hrang leh a lian zawng zawng siam rawh.
Bootstrap-a grid system hian container, row leh column hrang hrang hmangin content layout leh align a siam a. Flexbox hmanga siam a ni a, fully responsive a ni. A hnuaia tarlan te hi entirnan leh grid inzawmkhawm dan thuk taka thlir a ni.
Flexbox hmang thar emaw, hriat loh emaw? Background, terminology, guidelines, leh code snippets te hriat duh chuan he CSS Tricks flexbox guide hi chhiar la .
<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>
A chunga entirnan hian kan predefined grid class hmangin device tenau, lian, lian leh extra large-ah column zau zawng inang pathum a siam a. Chu column te chu page chhungah a laiah a awm a parent nen .container
.
Breaking it down, hetiang hian a hnathawh dan chu hetiang hi a ni:
- Container hian i site chhunga thil awmte chu center leh horizontal-a pad theihna tur kawng a pe a.
.container
Responsive pixel width.container-fluid
atan emawwidth: 100%
viewport leh device size zawng zawngah emaw hmang ang che . - Rows hi column hrang hranga wrapper a ni. Column tin hian
padding
an inkar space control nan horizontal (gutter an tih) an nei vek a. Chupadding
chu negative margin nei row-ah te counteract a ni. Chutiang chuan i column-a thu awm zawng zawng chu veilam sir hnuaiah hmuh theihin a inrem vek a ni. - Grid layout-ah chuan content chu column chhungah dah tur a ni a, column chauh chu rows fate nghal thei a ni.
- Flexbox vang hian grid column tarlan loh
width
chuan automatic in equal width column angin a layout ang. Entirnan, instance pali of.col-sm
will each automatically chu breakpoint te tak te atanga a chung lam atanga 25% zau a ni ang. Entirna dang chu auto-layout columns section -ah en rawh . - Column class-ah hian row khata column 12 awm thei zinga i hman duh zat a tarlang a. Chuvangin, equal-width column pathum across i duh chuan
.col-4
. - Column
width
s te hi percentage-a dah a nih avangin an parent element nena khaikhin chuan fluid leh size an nei reng a ni. padding
Column te hian column hrang hrang inkar gutter siam turin horizontal an nei a , mahse,margin
from rows lehpadding
from columns te chu.no-gutters
on the hmangin i paih thei a.row
ni.- Grid responsive tur chuan grid breakpoint panga a awm a, responsive breakpoint tin atan pakhat : breakpoint zawng zawng (extra small), small, medium, large, leh extra large.
- Grid breakpoints hi minimum width media query-a innghat a ni a, chu breakpoint pakhat leh a chunga awm zawng zawngah hman a ni tihna a ni (eg,
.col-sm-4
device tenau, lian, lian, leh extra large-ah hman a ni a, mahsexs
breakpoint hmasa ber erawh a ni lo). - Semantic markup tam zawk neih nan predefined grid class (like
.col-4
) emaw Sass mixins emaw i hmang thei bawk.
Flexbox chhehvela limitation leh bugs awmte hre reng ang che , HTML element thenkhat flex container atana hman theih loh ang chi te hi hre reng ang che .
Bootstrap hian size tam zawk definite nan em
s emaw s emaw a hmang laiin, s hi grid breakpoint leh container width atan hman a ni thung. Hei hi a chhan chu viewport width hi pixels a nih avangin font size nen a danglam lo .rem
px
Bootstrap grid system aspect hrang hrangte chu device tam takah handy table hmanga hnathawh dan en rawh.
A tlem zawk <576px |
A te ≥576px a ni |
A laihawl ≥768px a ni |
A lian ≥992px a ni |
A lian zawk ≥1200px |
|
---|---|---|---|---|---|
Max container zau zawng | A awm lo (auto) . | 540px a ni | 720px a ni | 960px a ni | 1140px a ni |
Class hmasa ber a ni | .col- |
.col-sm- |
.col-md- |
.col-lg- |
.col-xl- |
# of column hrang hrang a awm | 12 a ni | ||||
Gutter zau zawng | 30px (column sir lehlamah 15px) | ||||
Nestable a ni | Awle | ||||
Column order tur a ni | Awle |
.col-sm-6
. _
Entirnan, hetah hian grid layout pahnih kan rawn tarlang e, chu chu device leh viewport tinah hman theih a ni a, from xs
to xl
. Breakpoint i mamawh apiang atan unit-less class engzat pawh dah la, column tin chu a zau zawng inang vek a ni ang.
<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>
Equal-width column te hi line tam takah then theih a ni a, mahse Safari flexbox bug a awm a , hei hian explicit flex-basis
or border
. Browser version hlui zawkte tan chuan workaround a awm a, mahse i up-to-date chuan a tul tur a ni lo.
<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>
Flexbox grid column-te tana auto-layout hian column pakhat zau zawng i set thei a, a chhehvela unau column-te chu automatic-in a size i siamsak thei bawk. Grid class ruat lawk (a hnuaia tarlan ang hian), grid mixin, emaw inline width emaw i hmang thei bawk. Column dangte chu center column zau zawng engzat pawhin an size an thlak ang tih hre reng ang che.
<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>
Class hmangin col-{breakpoint}-auto
column te chu an content awm dan natural width atanga size tur a ni.
<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>
.w-100
Column te chu line thara break i duhna hmunah dahin row tam tak huam thei column zau zawng inang vek siam rawh . Break te chu responsive takin siam la , chu chu responsive display utilities.w-100
thenkhat nen mix la .
<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>
Bootstrap-a grid-ah hian complex responsive layout siamna tur predefined class tier panga a awm a. I column te size chu extra small, small, medium, large, or extra large device ah i duh angin customize rawh.
Device te ber atanga a lian ber thlenga grid inang tak tak tan chuan .col
and .col-*
class te hi hmang ang che. Column lian bik i mamawh hunah number nei class tarlang rawh; chutiang a nih loh chuan, zalen takin .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>
Class set khat hmangin .col-sm-*
basic grid system siam theih a ni a, chu chu stack-a tan a ni a, chutah chuan breakpoint te tak te ( sm
)-ah horizontal a nih hmain.
<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>
I column te chu grid tier thenkhatah stack mai mai turin i duh lo em ni? A tul angin tier tin tan class hrang hrang inzawmkhawm hmang ang che. A hnathawh zawng zawng hriatna tha zawk hriat duh chuan a hnuaia entîrna hi en rawh.
<!-- 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>
Column vertical leh horizontal-a align turin flexbox alignment utilities hmang ang che.
<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>
Kan grid class ruat lawk tawha column inkar gutter awmte chu .no-gutters
. Hei hian immediate children column zawng zawng atanga negative margin
s .row
leh horizontal te chu a paih chhuak vek a ni.padding
Heng style te siamna tur source code chu hetiang hi a ni. Column override te hi naupang column hmasa berte chauh scope a ni a, attribute selector hmanga target a ni tih hre reng ang che . Hei hian selector bik zawk a siam laiin, column padding chu spacing utilities hmangin a la siam danglam belh thei tho a ni .
Edge-to-edge design i mamawh em? Nu leh pa .container
emaw .container-fluid
.
Practice-ah chuan hetiang hian a lang. Hriat tur chu hei hi predefined grid class dang zawng zawng (column zau zawng, responsive tiers, reorder, leh a dangte pawh tel) nen i hmang chhunzawm thei ang.
<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>
Row khat chhunga column 12 aia tam dah a nih chuan, extra column group tinte chu unit pakhat angin line tharah an khuh ang.
9 + 4 = 13 > 12 a nih avangin he 4-column-wide div hi line thar pakhatah contiguous unit pakhat angin a wrapped a.
A hnuaia column te chu line thar zawh hian an chhunzawm zel a.
<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>
Flexbox-a line thara column break tur chuan hack tlemte a ngai a: width: 100%
i column te chu line thara wrap duhna hmun apiangah element dah la. A tlangpuiin hei hi multiple .row
s hmanga tihhlawhtlin a ni a, mahse implementation method zawng zawng hian hei hi a account thei lo.
<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>
He break hi breakpoint bik ah kan responsive display utilities hmangin i hmang thei bawk ang .
<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>
I thu awmte hmuh theiha awm dan.order-
tur control nan class hmang ang che . Heng class te hi responsive an nih avangin by breakpoint (eg, ) te chu i set thei a ni. Grid tier panga zawng zawngah through support a huam vek.order
.order-1.order-md-2
1
12
<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>
Responsive .order-first
leh .order-last
class te pawh order
element pakhat apply order: -1
leh order: 13
( order: $columns + 1
) hmanga thlak danglam thei class te pawh a awm bawk. .order-*
Heng class te hi a tul angin number pek class te nen pawh intermix theih a ni bawk .
<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>
Grid column te hi kawng hnih in offset theih a ni: kan responsive .offset-
grid class te leh kan margin utilities te . Grid class te hi column nena inmil turin size an siam a, margin erawh chu offset zau zawng danglam theihna hmuna quick layout atan a tangkai zawk thung.
.offset-md-*
Class hmangin column te chu dinglamah sawn rawh . Heng class te hian column pakhat veilam margin chu column hrang hrangin an tipung a *
. Entirnan, column pali chungah .offset-md-4
a kal thei..col-md-4
<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>
Responsive breakpoint-a column clearing bakah hian offsets reset a ngai mai thei. Hei hi grid entirnan action-ah en rawh .
<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>
v4-a flexbox-a kal hian margin utilities i hmang thei ang .mr-auto
, chu chu sibling column-te chu pakhat leh pakhat inkara inhlat tir ang chi hi a ni.
<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>
Default grid hmanga i content nest tur chuan column awmsa chhungah column thar .row
leh set dah la . Nested row-ah hian column set 12 emaw a aia tlem emaw add tur a awm tur a ni (column awm 12 awm zawng zawng hman vek a ngai lo)..col-sm-*
.col-sm-*
<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>
Bootstrap-a source Sass files i hman hian Sass variable leh mixins hmangin custom, semantic, leh responsive page layout siam theihna option i nei a ni. Kan predefined grid class te hian heng variable leh mixin ang chiah te hi hmangin fast responsive layouts atan ready-to-use class suite pum pui an pe thin.
Variables leh maps hian column awm zat, gutter zau zawng, leh floating column tanna tur media query point a tichiang a ni. Hengte hi a chunga kan document tawh predefined grid class te siam nan kan hmang a, chubakah a hnuaia custom mixins tarlan te tan pawh kan hmang bawk.
Mixins te hi grid variable te nen inzawmin grid column hrang hrang tan semantic CSS siam nan hman a ni.
Variable te chu i custom value ah i siam danglam thei a, a nih loh leh mixins te chu an default value nen i hmang mai thei bawk. Hetah hian default settings hmanga two-column layout siam dan tur entirnan kan rawn tarlang e, a inkarah gap awmin.
<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>
Kan built-in grid Sass variable leh maps hmang hian grid class ruahman lawk te chu a pumin kan customize theih a ni. Tier awm zat, media query dimension leh container zau zawng te thlak rawh—chutah recompile leh rawh.
Grid column awm zat hi Sass variable hmangin siam danglam theih a ni. $grid-columns
chu column pakhat zel zau zawng (za zela zela chhut) siam nan hman a ni a, chutih rualin breakpoint-specific widths chu column gutters inkar leh a tan pawh $grid-gutter-width
inang tlang taka then a phalsak bawk.padding-left
padding-right
Column ngei pawh kal pelin grid tier awm zat pawh i duh angin i siam thei bawk. Grid tier pali chauh i duh chuan $grid-breakpoints
and $container-max-widths
chu hetiang hian i update ang:
Sass variable emaw maps emaw i tihdanglam dawnin i tihdanglam chu i save a ngai ang a, i recompile a ngai ang. Chutianga tih chuan column width, offset, leh ordering atan predefined grid class set thar tak a output ang. Responsive visibility utilities te pawh custom breakpoints te hman theih turin update a ni bawk ang. Grid value te chu px
(not rem
, em
, or %
) ah set ngei ngei tur a ni.