Hoʻokumu ʻia ʻo Bootstrap ma luna o nā kolamu kolamu 12 pane, hoʻonohonoho, a me nā ʻāpana.
Hoʻohana ʻo Bootstrap i kekahi mau mea HTML a me nā waiwai CSS e koi ai i ka hoʻohana ʻana i ka HTML5 doctype. E hoʻokomo iā ia ma ka hoʻomaka o kāu mau papahana a pau.
- <!DOCTYPE html>
- <html lang = "en" >
- ...
- </html>
Hoʻonohonoho ʻo Bootstrap i ka hōʻike honua maʻamau, typography, a me nā ʻano loulou. ʻOiaʻiʻo, mākou:
margin
ma ke kinobackground-color: white;
ma kabody
@baseFontFamily
, @baseFontSize
, a me @baseLineHeight
nā hiʻohiʻona e like me kā mākou kumu kikokikona@linkColor
a hoʻopili i nā kaha lalo ma ka loulou:hover
Hiki ke loaʻa kēia mau ʻano i loko o ka scaffolding.less .
Me Bootstrap 2, ua hoʻokuʻu ʻia ka poloka hoʻonohonoho kahiko i makemake ʻia Normalize.css , kahi papahana e Nicolas Gallagher a me Jonathan Neal e mana pū ana i ka HTML5 Boilerplate . ʻOiai mākou e hoʻohana nui i ka Normalize i loko o kā mākou reset.less , ua wehe mākou i kekahi mau mea kikoʻī no Bootstrap.
Hoʻohana ka ʻōnaehana mākia Bootstrap i nā kolamu 12 , e hana ana i kahi ipu ākea 940px me ka ʻole o nā hiʻohiʻona pane . Me ka waihona CSS pane i hoʻohui ʻia, hoʻololi ka mākia i 724px a me 1170px ākea ma muli o kāu viewport. Ma lalo o 767px viewports, lilo nā kolamu i ka wai a hoʻopaʻa pololei.
No kahi hoʻolālā kolamu maʻalahi ʻelua, hana i kahi .row
a hoʻohui i ka helu kūpono o .span*
nā kolamu. No ka mea, he 12 mau kolamu kēia, e .span*
kau ana kēlā me kēia kolamu i ka helu o ia mau kolamu 12, a pono e hoʻohui mau i 12 no kēlā me kēia lālani (a i ʻole ka helu o nā kolamu ma ka makua).
- <div class = "lālani" >
- <div class = "span4" > ... </div>
- <div class = "span8" > ... </div>
- </div>
Hāʻawi ʻia i kēia laʻana, loaʻa iā mākou .span4
a me .span8
, e hana ana i 12 mau kolamu a me kahi lālani piha.
E hoʻoneʻe i nā kolamu i ka ʻākau me ka hoʻohana ʻana i .offset*
nā papa. Hoʻonui kēlā me kēia papa i ka ʻaoʻao hema o kahi kolamu me kahi kolamu holoʻokoʻa. No ka laʻana, .offset4
neʻe .span4
ma luna o ʻehā kolamu.
- <div class = "lālani" >
- <div class = "span4" > ... </div>
- <div class = "span3 offset2" > ... </div>
- </div>
No ka hoʻopili ʻana i kāu ʻike me ka mākia paʻamau, e hoʻohui i kahi kolamu hou .row
a me .span*
nā kolamu i loko o kahi .span*
kolamu e kū nei. Pono nā lālani i hoʻopaʻa ʻia he pūʻulu kolamu e hoʻohui i ka helu o nā kolamu o kona makua.
- <div class = "lālani" >
- <div class = "span9" >
- pae 1 kolamu
- <div class = "lālani" >
- <div class = "span6" > Papa 2 </div>
- <div class = "span3" > Papa 2 </div>
- </div>
- </div>
- </div>
Hoʻohana ka ʻōnaehana mānoanoa wai i nā pākēneka ma kahi o nā pika no ka laulā kolamu. Loaʻa iā ia nā mana pane like me kā mākou ʻōnaehana grid paʻa, e hōʻoiaʻiʻo ana i nā ʻāpana kūpono no nā ʻōkuhi pale kī a me nā mea hana.
Hana i kekahi lālani "wai" ma ka hoʻololi .row
ʻana i .row-fluid
. Noho like nā papa kolamu, e maʻalahi ka hoʻololi ʻana ma waena o nā grids paʻa a me ka wai.
- <div class = "laina-wai" >
- <div class = "span4" > ... </div>
- <div class = "span8" > ... </div>
- </div>
Hoʻohana like me ka hoʻololi ʻana i ka ʻōnaehana mākia paʻa: hoʻohui .offset*
i kekahi kolamu e hoʻopau ʻia e kēlā kolamu he nui.
- <div class = "laina-wai" >
- <div class = "span4" > ... </div>
- <div class = "span4 offset2" > ... </div>
- </div>
Hoʻohana ʻokoʻa ka hoʻohana ʻana i nā pūnana wai: pono e hoʻohui i kēlā me kēia pae o nā kolamu i 12 kolamu. ʻO kēia no ka hoʻohana ʻana o ka pā wai i nā pākēneka, ʻaʻole nā pika, no ka hoʻonohonoho ʻana i nā laula.
- <div class = "laina-wai" >
- <div class = "span12" >
- Waiwai 12
- <div class = "laina-wai" >
- <div class = "span6" >
- Waiwai 6
- <div class = "laina-wai" >
- <div class = "span6" > Wai 6 </div>
- <div class = "span6" > Wai 6 </div>
- </div>
- </div>
- <div class = "span6" > Wai 6 </div>
- </div>
- </div>
- </div>
Hāʻawi i kahi hoʻolālā laulā paʻa maʻamau (a me ke koho koho) me ka mea <div class="container">
pono wale nō.
- <kino>
- <div class = "container" >
- ...
- </div>
- </kino>
E hana i kahi ʻaoʻao wai, ʻelua kolamu me <div class="container-fluid">
- maikaʻi no nā noi a me nā palapala.
- <div class = "container-fluid" >
- <div class = "laina-wai" >
- <div class = "span2" >
- <!--Maʻiʻo ʻaoʻao-->
- </div>
- <div class = "span10" >
- <!--Maʻiʻo kino-->
- </div>
- </div>
- </div>
E ho'ā i ka CSS pane i kāu papahana ma o ka hoʻokomo ʻana i ka hōʻailona meta kūpono a me ka pepa ʻano hou i loko <head>
o kāu palapala. Inā ua hōʻuluʻulu ʻoe iā Bootstrap mai ka ʻaoʻao Customize, pono ʻoe e hoʻokomo i ka tag meta.
- <meta name = "viewport" maʻiʻo = "ākea=ākea-ākea, kumu-mua=1.0" >
- <link href = "nā waiwai/css/bootstrap-responsive.css" rel = "stylesheet" >
Nā poʻo i luna!ʻAʻole hoʻokomo ʻo Bootstrap i nā hiʻohiʻona pane i kēia manawa no ka mea ʻaʻole pono nā mea āpau e pane. Ma kahi o ka paipai ʻana i nā mea hoʻomohala e wehe i kēia hiʻohiʻona, manaʻo mākou ʻoi aku ka maikaʻi o ka hiki ke hiki iā ia ke pono.
Hiki i nā nīnau Media ke loaʻa CSS maʻamau e pili ana i nā kūlana he nui-nā ratios, ākea, ʻano hōʻikeʻike, a me nā mea ʻē aʻe—akā e nānā maʻamau a puni min-width
a max-width
.
E hoʻohana i nā nīnau media me ke kuleana a ma ke ʻano he hoʻomaka wale nō i kāu poʻe hoʻolohe kelepona. No nā papahana nui aʻe, e noʻonoʻo i nā waihona code i hoʻolaʻa ʻia a ʻaʻole nā papa o nā nīnau media.
Kākoʻo ʻo Bootstrap i kahi liʻiliʻi o nā nīnau media i hoʻokahi faila e kōkua i ka hoʻolilo ʻana i kāu mau papahana i kūpono i nā mea like ʻole a me nā hoʻonā pale. Eia ka mea i komo:
Lepili | Laulā hoʻolālā | laulā kolamu | Laulā ʻauwai |
---|---|---|---|
Hōʻike nui | 1200px a piʻi | 70px | 30px |
Default | 980px a i luna | 60px | 20px |
Nā papa kiʻi | 768px a i luna | 42px | 20px |
Nā kelepona i nā papa | 767px a lalo | Nā kolamu wai, ʻaʻohe laula paʻa | |
Kelepona | 480px a lalo | Nā kolamu wai, ʻaʻohe laula paʻa |
- /* Papakaukau nui */
- @media ( min - laula : 1200px ) { ... }
- /* Kiʻi papa i ka ʻāina a me ka pākaukau */
- @media ( min - laula : 768px ) a me ( max - laula : 979px ) { ... }
- /* Kelepona ʻāina i ka papa kiʻi kiʻi */
- @media ( ka nui - laula : 767px ) { ... }
- /* Nā kelepona ʻāina a i lalo */
- @media ( max - laula : 480px ) { ... }
No ka hoʻomohala wikiwiki ʻana i ka paʻa lima, e hoʻohana i kēia mau papa pono no ka hōʻike ʻana a me ka hūnā ʻana i nā ʻike e ka hāmeʻa. Aia ma lalo kahi papa o nā papa i loaʻa a me kā lākou hopena i kahi hoʻonohonoho nīnau nīnau media i hāʻawi ʻia (i hōʻailona ʻia e ka mea hana). Hiki ke loaʻa iā lākou ma responsive.less
.
Papa | Kelepona767px a lalo | Papa papa979px i 768px | PapahanaDefault |
---|---|---|---|
.visible-phone |
ʻIke ʻia | Huna | Huna |
.visible-tablet |
Huna | ʻIke ʻia | Huna |
.visible-desktop |
Huna | Huna | ʻIke ʻia |
.hidden-phone |
Huna | ʻIke ʻia | ʻIke ʻia |
.hidden-tablet |
ʻIke ʻia | Huna | ʻIke ʻia |
.hidden-desktop |
ʻIke ʻia | ʻIke ʻia | Huna |
E hoʻohana ma ka palena palena a pale i ka hana ʻana i nā mana like ʻole o ka pūnaewele hoʻokahi. Akā, e hoʻohana iā lākou e hoʻokō i ka hōʻike ʻana o kēlā me kēia hāmeʻa. ʻAʻole pono e hoʻohana ʻia nā pono hana pane me nā papa, a no laila ʻaʻole i kākoʻo ʻia.
E hoʻololi i kāu polokalamu kele pūnaewele a hoʻouka paha i nā mea like ʻole e hoʻāʻo i nā papa ma luna.
Hōʻike ʻia nā kaha ʻōmaʻomaʻo e ʻike ʻia ka papa ma kāu awa nānā i kēia manawa.
Maʻaneʻi, hōʻike ʻia nā kaha ʻōmaʻomaʻo e hūnā ʻia ka papa i kāu ʻike ʻike i kēia manawa.