Rekọja si akoonu akọkọ Rekọja si lilọ kiri awọn iwe aṣẹ
in English

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, CDN orisun ṣiṣi ọfẹ. Lilo oluṣakoso package tabi nilo lati ṣe igbasilẹ awọn faili orisun bi? Lọ 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 href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

JS

Ọpọlọpọ awọn paati wa nilo lilo JavaScript lati ṣiṣẹ. Ni pataki, wọn nilo awọn afikun JavaScript tiwa ati Popper . Fi ọkan ninu awọn atẹle wọnyi <script>si opin awọn oju-iwe rẹ, ni kete ṣaaju </body>tag pipade, lati mu wọn ṣiṣẹ.

Lapapo

Ṣafikun gbogbo ohun itanna JavaScript Bootstrap ati igbẹkẹle pẹlu ọkan ninu awọn edidi meji wa. Mejeeji bootstrap.bundle.jsati bootstrap.bundle.min.jspẹlu Popper fun awọn imọran irinṣẹ wa ati awọn agbejade. Fun alaye diẹ sii nipa ohun ti o wa ninu Bootstrap, jọwọ wo apakan awọn akoonu wa.

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

Lọtọ

Ti o ba pinnu lati lọ pẹlu ojutu awọn iwe afọwọkọ lọtọ, Popper gbọdọ wa ni akọkọ (ti o ba nlo awọn imọran irinṣẹ tabi awọn agbejade), ati lẹhinna awọn afikun JavaScript wa.

<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>

Awọn modulu

Ti o ba lo <script type="module">, jọwọ tọka si lilo Bootstrap wa bi apakan module .

Awọn eroja

Ṣe iyanilenu iru awọn paati wo ni o nilo JavaScript ati Popper wa ni gbangba? 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 )
  • Awọn awoṣe fun iṣafihan, ipo, ati ihuwasi yi lọ
  • Navbar fun faagun ohun itanna Collapse wa lati ṣe ihuwasi idahun
  • Offcanvases fun ifihan, ipo, ati ihuwasi yi lọ
  • Toasts fun ifihan ati yiyọ kuro
  • Awọn imọran irinṣẹ ati awọn agbejade fun iṣafihan ati ipo (tun nilo Popper )
  • 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">

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

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

    <!-- Optional JavaScript; choose one of the two! -->

    <!-- Option 1: Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

    <!-- Option 2: Separate Popper and Bootstrap JS -->
    <!--
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
    -->
  </body>
</html>

Fun awọn igbesẹ ti o tẹle, ṣ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">

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 ẹni-kẹ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.

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

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