Wɔasi bootstrap wɔ grids a ɛyɛ 12-column a ɛyɛ adwuma, nhyehyɛe, ne nneɛma a ɛwom so.
Bootstrap de HTML nneɛma bi ne CSS agyapade a ɛhwehwɛ sɛ wɔde HTML5 doctype no di dwuma di dwuma. Fa ka ho wɔ wo nnwuma nyinaa mfiase.
- <!NKYERƐWDE html>
- <html lang = "tw" >
- ...
- </html> na ɛwɔ hɔ
Bootstrap hyehyɛ wiase nyinaa nkyerɛkyerɛmu titiriw, typography, ne link styles. Ne titiriw no, yɛ:
margin
nipadua no sobackground-color: white;
no sobody
@baseFontFamily
, @baseFontSize
, ne @baseLineHeight
su ahorow no di dwuma sɛ yɛn nkyerɛwee nnyinaso@linkColor
na fa link underlines nkutoo di dwuma wɔ so:hover
Wobetumi ahu saa akwan yi wɔ scaffolding.less .
Bootstrap 2 no, wɔagyae reset block dedaw no de agye Normalize.css , adwuma a Nicolas Gallagher ne Jonathan Neal yɛe a ɛno nso ma HTML5 Boilerplate no tumi . Bere a yɛde Normalize no fã kɛse no ara di dwuma wɔ yɛn reset.less mu no, yɛayi nneɛma bi afi hɔ titiriw ama Bootstrap.
Default Bootstrap grid system no de columns 12 di dwuma , a ɛma wonya 940px wide container a enni mmuaeɛ features no adwuma. Sɛ wode CSS fael a ɛyɛ mmuae no ka ho a, grid no dannan ne ho ma ɛyɛ 724px ne 1170px trɛw a egyina wo viewport so. Wɔ 767px viewports ase no, columns no bɛyɛ fluid na stack vertically.
Sɛ wopɛ sɛ wonya nkyerɛwde abien nhyehyɛe a ɛnyɛ den a, yɛ a .row
na fa .span*
nkyerɛwde dodow a ɛfata ka ho. Esiane sɛ eyi yɛ grid a ɛwɔ nkyerɛwde 12 nti, emu biara .span*
trɛw saa nkyerɛwde 12 no dodow bi mu, na ɛsɛ sɛ bere nyinaa ka ho kosi 12 ma nkyerɛwde biara (anaasɛ nkyerɛwde dodow a ɛwɔ ɔwofo no mu).
- <div adesuakuw = "row" >
- <div adesuakuw = "span4" > ... </div>
- <div adesuakuw = "span8" > ... </div>
- </div> no
Sɛ yɛde saa nhwɛso yi ma a, yɛwɔ .span4
ne .span8
, a ɛma wonya nkyerɛwde 12 a wɔaka abom ne row a edi mũ.
Fa nkyerɛwde ahorow no kɔ nifa denam .offset*
adesua ahorow so. Adesuakuw biara ma kɔla bi benkum so no kɔ soro kɔla mũ nyinaa. Sɛ nhwɛso no, .offset4
ɛkɔfa .span4
adum anan so.
- <div adesuakuw = "row" >
- <div adesuakuw = "span4" > ... </div>
- <div adesuakuw = "span3 offset2" > ... </div> . Ɔde ne nsa kyerɛɛ ne so, na ɔde ne nsa kyerɛɛ ne so
- </div> no
Sɛ wopɛ sɛ wode default grid no hyɛ wo nsɛm no mu a, fa kɔla foforo .row
ne .span*
nkyerɛwde ahorow ka ho wɔ .span*
kɔla bi a ɛwɔ hɔ dedaw no mu. Ɛsɛ sɛ nested rows no de columns ahorow a ɛka bom yɛ columns dodow a ɛwɔ n’awofo no ka ho.
- <div adesuakuw = "row" >
- <div adesuakuw = "span9" >
- Level 1 kɔla a ɛto so 1 no
- <div adesuakuw = "row" >
- <div adesuakuw = "span6" > Ɔfa 2 </div>
- <div adesuakuw = "span3" > Ɔfa 2 </div>
- </div> no
- </div> no
- </div> no
Nsu grid nhyehyɛe no de ɔha biara mu nkyem di dwuma sen sɛ wɔde piksel bedi dwuma ma adum trɛw. Ɛwɔ mmuaeɛ tumi te sɛ yɛn fixed grid nhyehyɛeɛ no, ɛhwɛ ma proportions a ɛfata ma key screen resolutions ne devices.
Yɛ row biara "nsu" denam nsakrae a wobɛsakra .row
ayɛ no .row-fluid
. Adum adesua ahorow no kɔ so tra hɔ sɛnea ɛte no ara pɛpɛɛpɛ, na ɛma ɛyɛ mmerɛw sɛ wobɛdannan grid a ɛyɛ pintinn ne nea ɛyɛ nsu ntam.
- <div adesuakuw = "row-nsu" >
- <div adesuakuw = "span4" > ... </div>
- <div adesuakuw = "span8" > ... </div>
- </div> no
Ɛyɛ adwuma ɔkwan koro no ara so sɛnea fixed grid system offsetting: fa ka .offset*
column biara ho ma offset denam column dodow no so.
- <div adesuakuw = "row-nsu" >
- <div adesuakuw = "span4" > ... </div>
- <div adesuakuw = "span4 ɔfase2" > ... </div>
- </div> no
Fluid grids de nesting di dwuma ɔkwan soronko so: ɛsɛ sɛ nested level biara a ɛwɔ columns no mu no de columns 12 ka ho. Eyi te saa efisɛ nsu grid no de ɔha biara mu nkyekyem di dwuma, na ɛnyɛ piksel, de hyehyɛ ntrɛwmu.
- <div adesuakuw = "row-nsu" >
- <div adesuakuw = "span12" >
- Nsu a ɛwɔ mu 12
- <div adesuakuw = "row-nsu" >
- <div adesuakuw = "span6" >
- Nsu a ɛwɔ mu 6
- <div adesuakuw = "row-nsu" >
- <div adesuakuw = "span6" > Nsu 6 </div>
- <div adesuakuw = "span6" > Nsu 6 </div>
- </div> no
- </div> no
- <div adesuakuw = "span6" > Nsu 6 </div>
- </div> no
- </div> no
- </div> no
Ɛde fixed-width (na sɛ wopɛ sɛ ɛyɛ mmuae) nhyehyɛe a wɔtaa de di dwuma a <div class="container">
ɛho hia nkutoo ma.
- <nipadua>
- <div adesuakuw = "adekorabea" >
- ...
- </div> no
- </nipadua>
Yɛ kratafa a ɛyɛ nsu, a ɛwɔ adum abien a —ɛyɛ <div class="container-fluid">
papa ma application ne docs.
- <div class = "ahina-nsuo" >
- <div adesuakuw = "row-nsu" >
- <div adesuakuw = "span2" >
- <!--Sidebar mu nsɛm-->
- </div> no
- <div adesuakuw = "span10" >
- <!--Nipadua mu nsɛm-->
- </div> no
- </div> no
- </div> no
Dane responsive CSS wɔ wo project no mu denam meta tag a ɛfata ne stylesheet foforo <head>
a wode bɛka wo document no mu no so. Sɛ woaboaboa Bootstrap ano afi Customize krataafa no so a, nea ehia sɛ wode meta tag no nkutoo ka ho.
- <meta din = "hwɛbea" nsɛm = "trɛw=mfiri-trɛw, mfiase-nsusuwii=1.0" >
- <link href = "agyapadeɛ/css/bootstrap-mmuaeɛ.css" rel = "ɔkwan so krataa" >
Ti a ɛwɔ soro!Bootstrap nka mmuaeɛ features default saa berɛ yi sɛdeɛ ɛnyɛ biribiara na ɛhia sɛ ɛyɛ responsive. Sɛ́ anka yɛbɛhyɛ wɔn a wɔyɛ nneɛma no nkuran ma wonyi saa ade yi mfi hɔ no, yesusuw ho sɛ eye sɛ yɛbɛma ayɛ adwuma sɛnea ɛho hia.
Media nsɛmmisa ma kwan ma CSS a wɔahyɛ da ayɛ a egyina tebea horow bi so—nsusuwii, ntrɛwmu, ɔyɛkyerɛ su, ne nea ɛkeka ho—nanso ɛtaa twe adwene si min-width
ne max-width
.
Fa nsɛm ho amanneɛbɔfo nsɛmmisa di dwuma wɔ asɛyɛde mu na ɛyɛ mfiase nkutoo ma wo mobile atiefo. Sɛ wopɛ nnwuma akɛse a, yɛ susuw dedicated code bases ho na ɛnyɛ layers of media queries.
Bootstrap boa media nsɛmmisa kakraa bi wɔ fael biako mu de boa ma wo nnwuma no fata kɛse wɔ mfiri ahorow ne screen resolutions so. Nea ɛka ho ni:
Ahyɛnsoɔ | Nhyehyɛe no trɛw | Kɔla no trɛw | Gutter no trɛw |
---|---|---|---|
Nneɛma kɛse a wɔde kyerɛ | 1200px ne nea ɛboro saa | 70px na ɛyɛ | 30px na ɛyɛ |
Mfiaseɛ | 980px ne nea ɛboro saa | 60px na ɛyɛ | 20px na ɛyɛ |
Mfonini a wɔde ayɛ abopon | 768px ne nea ɛboro saa | 42px na ɛyɛ | 20px na ɛyɛ |
Telefon a wɔde di dwuma wɔ tablɛt so | 767px ne nea ɛwɔ ase ha | Nsu adum, enni ntrɛwmu a wɔahyɛ da ayɛ | |
Tɛlɛfon ahorow | 480px ne nea ɛwɔ ase ha | Nsu adum, enni ntrɛwmu a wɔahyɛ da ayɛ |
- /* Desktop kɛseɛ */
- @media ( min - trɛw : 1200px ) { ... }.
- /* Mfonini tablet a ɛkɔ asase ne desktop so */
- @media ( min - trɛw : 768px ) ne ( max - trɛw : 979px ) { ... }.
- /* Asase so telefon a wɔde yɛ mfonini tablet */
- @media ( max - trɛw : 767px ) { ... }.
- /* Landscape fon ahorow ne ase */
- @media ( max - trɛw : 480px ) { ... }.
Sɛ wopɛ sɛ woyɛ mobile-friendly ntɛmntɛm a, fa saa utility class ahorow yi di dwuma fa kyerɛ na wode nneɛma sie denam mfiri so. Ase hɔ no yɛ table a ɛkyerɛ adesua ahorow a ɛwɔ hɔ ne wɔn nkɛntɛnso wɔ media asɛmmisa nhyehyɛe bi a wɔde ama (a wɔde mfiri ahyɛ no agyirae). Wobetumi ahu wɔn wɔ responsive.less
.
Klaase | Tɛlɛfon ahorow767px ne nea ɛwɔ ase ha | Nnuru a wɔde yɛ aduru979px na ɛyɛ 768px | Desktop ahorow a wɔde di dwumaMfiaseɛ |
---|---|---|---|
.visible-phone |
Nea wotumi hu | Asuma | Asuma |
.visible-tablet |
Asuma | Nea wotumi hu | Asuma |
.visible-desktop |
Asuma | Asuma | Nea wotumi hu |
.hidden-phone |
Asuma | Nea wotumi hu | Nea wotumi hu |
.hidden-tablet |
Nea wotumi hu | Asuma | Nea wotumi hu |
.hidden-desktop |
Nea wotumi hu | Nea wotumi hu | Asuma |
Fa di dwuma wɔ anohyeto mu na kwati sɛ wobɛbɔ wɛbsaet koro no ara nkyerɛase ahorow a ɛsono emu biara koraa. Mmom no, fa di dwuma de ka mfiri biara a wɔde bɛkyerɛkyerɛ mu no ho. Ɛnsɛ sɛ wɔde utilities a ɛma mmuae di dwuma wɔ tables ho, na sɛnea ɛte no, wɔmfa mmoa.
Sesa wo browser no kɛse anaa fa gu mfiri ahorow so de sɔ atifi hɔ adesua ahorow no hwɛ.
Green checkmarks kyerɛ sɛ class no da adi wɔ wo mprempren viewport no mu.
Ɛha yi, green checkmarks kyerɛ sɛ class no ahintaw wɔ wo mprempren viewport no mu.