Parancah

Bootstrap diwangun dina grids 12-kolom responsif, perenah, sareng komponén.

Merlukeun HTML5 doctype

Bootstrap ngagunakeun elemen HTML tangtu jeung sipat CSS nu merlukeun pamakéan doctype HTML5. Lebetkeun éta dina awal sadaya proyék anjeun.

  1. <!DOCTYPE html>
  2. <html lang = "en" >
  3. ...
  4. </html>

Tipografi sareng tautan

Bootstrap nyetél tampilan global dasar, tipografi, sareng gaya tautan. Sacara husus, urang:

  • Leupaskeun marginkana awak
  • Disetél background-color: white;dinabody
  • Anggo @baseFontFamily, @baseFontSize, sareng @baseLineHeightatribut salaku dasar tipografi urang
  • Setel warna link global via @linkColorjeung nerapkeun link underlines ngan dina:hover

Gaya ieu tiasa dipendakan dina parancah.less .

Reset via Normalize

Kalawan Bootstrap 2, blok reset heubeul geus turun dina ni'mat Normalize.css , proyék ku Nicolas Gallagher nu ogé kakuatan HTML5 Boilerplate . Nalika kami nganggo seueur Normalize dina reset.less kami , kami parantos ngaleungitkeun sababaraha elemen khusus pikeun Bootstrap.

conto Live grid

Sistem grid Bootstrap standar ngagunakeun 12 kolom , sahingga pikeun wadahna lega 940px tanpa fitur responsif diaktipkeun. Jeung file CSS responsif ditambahkeun, grid nu diluyukeun jadi 724px na 1170px lega gumantung kana viewport Anjeun. Di handap 767px viewports, kolom jadi cair jeung tumpukan vertikal.

1
1
1
1
1
1
1
1
1
2
3
4
4
5
9

Dasar grid HTML

Pikeun perenah dua kolom basajan, nyieun hiji .rowtur nambahkeun jumlah luyu .span*kolom. Kusabab ieu grid 12-kolom, unggal .span*ngawengku jumlah maranéhanana 12 kolom, sarta kudu salawasna nambahan nepi ka 12 pikeun tiap baris (atawa jumlah kolom dina indungna).

  1. <div class = "baris" >
  2. <div class = "span4" > ... </div>
  3. <div class = "span8" > ... </div>
  4. </div>

Dibikeun conto ieu, urang kudu .span4na .span8, sahingga pikeun 12 total kolom sarta baris lengkep.

Ngimbangkeun kolom

Pindahkeun kolom ka katuhu nganggo .offset*kelas. Unggal kelas ngaronjatkeun margin kénca kolom ku sakabeh kolom. Contona, .offset4ngalir .span4ngaliwatan opat kolom.

4
3 ngébréhkeun 2
3 nyelap 1
3 ngébréhkeun 2
6 udag 3
  1. <div class = "baris" >
  2. <div class = "span4" > ... </div>
  3. <div class = "span3 offset2" > ... </div>
  4. </div>

Kolom nyarang

Pikeun nyarang eusi anjeun sareng grid standar, tambahkeun kolom anyar .rowsareng set dina .span*kolom anu tos aya .span*. Baris bersarang kedah kalebet sakumpulan kolom anu nambihan kana jumlah kolom indungna.

Kolom Level 1
Tingkat 2
Tingkat 2
  1. <div class = "baris" >
  2. <div class = "span9" >
  3. Kolom Level 1
  4. <div class = "baris" >
  5. <div class = "span6" > Level 2 </div>
  6. <div class = "span3" > Level 2 </div>
  7. </div>
  8. </div>
  9. </div>

conto grid cairan hirup

Sistem grid cairan ngagunakeun persen tinimbang piksel pikeun rubak kolom. Éta gaduh kamampuan responsif anu sami sareng sistem grid tetep urang, mastikeun proporsi anu pas pikeun résolusi layar konci sareng alat.

1
1
1
1
1
1
1
1
1
1
1
1
4
4
4
4
8
6
6
12

Dasar cairan grid HTML

Jieun sagala baris "cairan" ku ngarobah .rowkana .row-fluid. Kelas kolom tetep sami, sahingga gampang flip antara grid tetep sareng cairan.

  1. <div class = "baris-cairan" >
  2. <div class = "span4" > ... </div>
  3. <div class = "span8" > ... </div>
  4. </div>

Ngurangan cairan

Ngoperasikeun cara nu sarua salaku sistem grid tetep offsetting: tambahkeun .offset*ka kolom mana wae pikeun offset ku nu loba kolom.

4
4 nyelap 4
3 ngébréhkeun 3
3 ngébréhkeun 3
6 uwih 6
  1. <div class = "baris-cairan" >
  2. <div class = "span4" > ... </div>
  3. <div class = "span4 offset2" > ... </div>
  4. </div>

Cairan nyarang

Nyarang sareng kisi cairan rada béda: jumlah kolom anu disarangkeun teu kedah cocog sareng jumlah kolom indungna. Gantina, unggal tingkat kolom nested direset sabab unggal baris nyokot 100% tina kolom indungna.

Cairan 12
Cairan 6
Cairan 6
  1. <div class = "baris-cairan" >
  2. <div class = "span12" >
  3. Cairan 12
  4. <div class = "baris-cairan" >
  5. <div class = "span6" > Cairan 6 </div>
  6. <div class = "span6" > Cairan 6 </div>
  7. </div>
  8. </div>
  9. </div>

perenah maneuh

Nyayogikeun perenah lebar tetep (sareng opsional responsif) kalayan ngan ukur <div class="container">diperyogikeun.

  1. <awak>
  2. <div class = "wadah" >
  3. ...
  4. </div>
  5. </body>

Fluid layout

Create a fluid, two-column page with <div class="container-fluid">—great for applications and docs.

  1. <div class="container-fluid">
  2. <div class="row-fluid">
  3. <div class="span2">
  4. <!--Sidebar content-->
  5. </div>
  6. <div class="span10">
  7. <!--Body content-->
  8. </div>
  9. </div>
  10. </div>

Enabling responsive features

Turn on responsive CSS in your project by including the proper meta tag and additional stylesheet within the <head> of your document. If you've compiled Bootstrap from the Customize page, you need only include the meta tag.

  1. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  2. <link href="assets/css/bootstrap-responsive.css" rel="stylesheet">

Heads up! Bootstrap doesn't include responsive features by default at this time as not everything needs to be responsive. Instead of encouraging developers to remove this feature, we figure it best to enable it as needed.

About responsive Bootstrap

Paranti responsif

Media queries allow for custom CSS based on a number of conditions—ratios, widths, display type, etc—but usually focuses around min-width and max-width.

  • Modify the width of column in our grid
  • Stack elements instead of float wherever necessary
  • Resize headings and text to be more appropriate for devices

Use media queries responsibly and only as a start to your mobile audiences. For larger projects, do consider dedicated code bases and not layers of media queries.

Supported devices

Bootstrap supports a handful of media queries in a single file to help make your projects more appropriate on different devices and screen resolutions. Here's what's included:

Label Layout width Column width Gutter width
Large display 1200px and up 70px 30px
Default 980px and up 60px 20px
Portrait tablets 768px and above 42px 20px
Phones to tablets 767px and below Fluid columns, no fixed widths
Phones 480px and below Fluid columns, no fixed widths
  1. /* Large desktop */
  2. @media (min-width: 1200px) { ... }
  3.  
  4. /* Portrait tablet to landscape and desktop */
  5. @media (min-width: 768px) and (max-width: 979px) { ... }
  6.  
  7. /* Landscape phone to portrait tablet */
  8. @media (max-width: 767px) { ... }
  9.  
  10. /* Landscape phones and down */
  11. @media (max-width: 480px) { ... }

Responsive utility classes

For faster mobile-friendly development, use these utility classes for showing and hiding content by device. Below is a table of the available classes and their effect on a given media query layout (labeled by device). They can be found in responsive.less.

Class Phones 767px and below Tablets 979px to 768px Desktops Default
.visible-phone Visible
.visible-tablet Visible
.visible-desktop Visible
.hidden-phone Visible Visible
.hidden-tablet Visible Visible
.hidden-desktop Visible Visible

When to use

Use on a limited basis and avoid creating entirely different versions of the same site. Instead, use them to complement each device's presentation. Responsive utilities should not be used with tables, and as such are not supported.

Responsive utilities test case

Resize your browser or load on different devices to test the above classes.

Visible on...

Green checkmarks indicate that class is visible in your current viewport.

  • Phone✔ Telepon
  • Tablet✔ Tablet
  • Desktop✔ Desktop

Hidden on...

Di dieu, centang héjo nunjukkeun yén kelas disumputkeun dina viewport anjeun ayeuna.

  • Telepon✔ Telepon
  • Tablét✔ Tablet
  • Desktop✔ Desktop