Source

Ifaara

Bẹrẹ pẹlu Bootstrap, ilana olokiki julọ ni agbaye fun kikọ idahun, awọn aaye alagbeka-akọkọ, pẹlu jsDelivr ati oju-iwe ibẹrẹ awoṣe.

Ibẹrẹ kiakia

Ṣe o n wa lati yara ṣafikun Bootstrap si iṣẹ akanṣe rẹ? Lo jsDelivr, ti a pese fun ọfẹ nipasẹ awọn eniya ni jsDelivr. Lilo oluṣakoso package tabi nilo lati ṣe igbasilẹ awọn faili orisun bi? Ori si oju-iwe gbigba lati ayelujara.

CSS

Daakọ-lẹẹmọ iwe aṣa naa <link>sinu rẹ <head>ṣaaju gbogbo awọn iwe aṣa miiran lati gbe CSS wa.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

JS

Ọpọlọpọ awọn paati wa nilo lilo JavaScript lati ṣiṣẹ. Ni pato, wọn nilo jQuery , Popper.js , ati awọn afikun JavaScript tiwa. Gbe awọn wọnyi <script>s sunmọ opin ti awọn oju-iwe rẹ, ni ọtun ṣaaju </body>tag pipade, lati mu wọn ṣiṣẹ. jQuery gbọdọ wa ni akọkọ, lẹhinna Popper.js, ati lẹhinna awọn afikun JavaScript wa.

A lo jQuery's slim build , ṣugbọn ẹya kikun tun ṣe atilẹyin.

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

Ṣe iyanilenu iru awọn paati wo ni o nilo taara jQuery, JS wa, ati Popper.js? Tẹ ọna asopọ awọn paati ifihan ni isalẹ. Ti o ko ba ni idaniloju rara nipa eto oju-iwe gbogbogbo, tẹsiwaju kika fun apẹrẹ oju-iwe apẹẹrẹ.

Ṣe afihan awọn paati ti o nilo JavaScript
  • Awọn itaniji fun yiyọ kuro
  • Awọn bọtini fun awọn ipinlẹ toggling ati apoti / iṣẹ redio
  • Carousel fun gbogbo awọn ihuwasi ifaworanhan, awọn idari, ati awọn olufihan
  • Collapse fun yiyi hihan akoonu
  • Awọn isubu fun iṣafihan ati ipo (tun nilo Popper.js )
  • Awọn awoṣe fun iṣafihan, ipo, ati ihuwasi yi lọ
  • Navbar fun faagun ohun itanna Collapse wa lati ṣe ihuwasi idahun
  • Awọn imọran irinṣẹ ati awọn agbejade fun iṣafihan ati ipo (tun nilo Popper.js )
  • Scrollspy fun ihuwasi lilọ kiri ati awọn imudojuiwọn lilọ kiri

Awoṣe ibẹrẹ

Rii daju pe o ṣeto awọn oju-iwe rẹ pẹlu apẹrẹ tuntun ati awọn iṣedede idagbasoke. Iyẹn tumọ si lilo iwe-ẹkọ HTML5 kan ati pẹlu tag meta wiwo wiwo fun awọn ihuwasi idahun to dara. Fi gbogbo rẹ papọ ati awọn oju-iwe rẹ yẹ ki o dabi eyi:

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

    <title>Hello, world!</title>
  </head>
  <body>
    <h1>Hello, world!</h1>

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  </body>
</html>

Iyẹn ni gbogbo ohun ti o nilo fun awọn ibeere oju-iwe gbogbogbo. Ṣabẹwo si awọn iwe aṣẹ Ifilelẹ tabi awọn apẹẹrẹ osise wa lati bẹrẹ fifi akoonu ati awọn paati aaye rẹ jade.

Awọn agbaye pataki

Bootstrap nlo iwonba ti awọn aza agbaye pataki ati awọn eto ti iwọ yoo nilo lati mọ nigba lilo rẹ, gbogbo eyiti o fẹrẹ jẹ iyasọtọ iyasọtọ si ọna deede ti awọn aṣa aṣawakiri agbelebu. Jẹ ká besomi ni.

HTML5 doctype

Bootstrap nilo lilo HTML5 doctype. Laisi rẹ, iwọ yoo rii diẹ ninu aṣa iselona ti ko pe, ṣugbọn pẹlu rẹ ko yẹ ki o fa awọn osuke nla eyikeyi.

<!doctype html>
<html lang="en">
  ...
</html>

Idahun meta tag

Bootstrap jẹ idagbasoke alagbeka ni akọkọ , ilana kan ninu eyiti a ṣe iṣapeye koodu fun awọn ẹrọ alagbeka ni akọkọ ati lẹhinna ṣe iwọn awọn paati bi o ṣe pataki nipa lilo awọn ibeere media CSS. Lati rii daju imudara to dara ati fifọwọkan sun-un fun gbogbo awọn ẹrọ, ṣafikun ami ami oju opo wiwo idahun si faili rẹ <head>.

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

O le wo apẹẹrẹ eyi ni iṣe ni awoṣe ibẹrẹ .

Apoti-iwọn

Fun iwọn taara diẹ sii ni CSS, a yipada box-sizingiye agbaye lati content-boxsi border-box. Eyi ni idaniloju paddingko ni ipa lori iwọn iṣiro ipari ti ipin kan, ṣugbọn o le fa awọn iṣoro pẹlu diẹ ninu sọfitiwia ẹnikẹta bii Google Maps ati Ẹrọ Iwadi Aṣa Google.

Ni iṣẹlẹ ti o ṣọwọn o nilo lati fagilee rẹ, lo nkan bi atẹle:

.selector-for-some-widget {
  box-sizing: content-box;
}

Pẹlu snippet ti o wa loke, awọn eroja itẹ-ẹiyẹ — pẹlu akoonu ti ipilẹṣẹ nipasẹ ::beforeati ::after— yoo gbogbo jogun pato box-sizingfun iyẹn .selector-for-some-widget.

Kọ ẹkọ diẹ sii nipa awoṣe apoti ati iwọn ni Awọn ẹtan CSS .

Atunbere

Fun imudara aṣawakiri aṣawakiri, a lo Atunbere lati ṣatunṣe awọn aiṣedeede kọja awọn aṣawakiri ati awọn ẹrọ lakoko ti o pese awọn atunto ero diẹ diẹ si awọn eroja HTML ti o wọpọ.

Agbegbe

Duro titi di oni lori idagbasoke Bootstrap ki o de ọdọ agbegbe pẹlu awọn orisun iranlọwọ wọnyi.

  • Tẹle @getbootstrap lori Twitter .
  • Ka ati ṣe alabapin si Bulọọgi Bootstrap osise naa .
  • Wiregbe pẹlu awọn Bootstrappers ẹlẹgbẹ ni IRC. Lori irc.freenode.netolupin, ni ##bootstrapikanni.
  • Iranlọwọ imuse ni a le rii ni Stack Overflow (ti samisi bootstrap-4).
  • Awọn olupilẹṣẹ yẹ ki o lo koko-ọrọ bootstraplori awọn idii eyiti o yipada tabi ṣafikun si iṣẹ ṣiṣe ti Bootstrap nigbati o n pin kaakiri nipasẹ npm tabi awọn ọna ifijiṣẹ ti o jọra fun wiwa ti o pọju.

O tun le tẹle @getbootstrap lori Twitter fun olofofo tuntun ati awọn fidio orin oniyi.