Fa'ase'e ile anotusi autu Fa'ase'e ile su'ega fa'amatalaga
Check
in English

Fa'amau

Fa'aoga sitaili fa'aautu masani a Bootstrap mo gaioiga i fomu, talanoaga, ma isi mea fa'atasi ai ma le lagolago mo le tele o lapopoa, setete, ma isi mea.

Faataitaiga

O le Bootstrap e aofia ai le tele o sitaili faʻamaufaʻailogaina faʻamau, o loʻo faʻaogaina e taʻitasi lona lava faʻamoemoega faʻapitoa, faʻatasi ai ma nai mea faʻaopoopo e lafo i totonu mo le sili atu le pulea.

html
<button type="button" class="btn btn-primary">Primary</button>
<button type="button" class="btn btn-secondary">Secondary</button>
<button type="button" class="btn btn-success">Success</button>
<button type="button" class="btn btn-danger">Danger</button>
<button type="button" class="btn btn-warning">Warning</button>
<button type="button" class="btn btn-info">Info</button>
<button type="button" class="btn btn-light">Light</button>
<button type="button" class="btn btn-dark">Dark</button>

<button type="button" class="btn btn-link">Link</button>
Tu'uina atu le uiga i tekinolosi fesoasoani

O le fa'aogaina o le lanu e fa'aopoopo ai le uiga e na'o se fa'aaliga va'aia, e le fa'ailoa atu i tagata fa'aoga o tekonolosi fesoasoani - e pei o le au faitau mata. Ia fa'amautinoa o fa'amatalaga o lo'o fa'ailogaina i le lanu e manino mai le anotusi lava ia (fa'ata'ita'iga o tusitusiga va'aia), pe fa'aofi mai i isi auala, e pei o tusitusiga fa'aopoopo natia i le .visually-hiddenvasega.

Taofi le afifiina o tusitusiga

Afai e te le mana'o e afifi le ki, e mafai ona e fa'aopoopo le .text-nowrapvasega ile fa'amau. I le Sass, e mafai ona e seti $btn-white-space: nowrape faʻamalo le afifiina o tusitusiga mo faʻamau taʻitasi.

Fa'ailoga fa'amau

O .btnvasega ua mamanuina e faʻaaogaina ma le <button>elemene. Ae ui i lea, e mafai foʻi ona e faʻaogaina nei vasega i luga <a>poʻo <input>elemene (e ui o nisi tagata suʻesuʻe e mafai ona faʻaogaina se faʻaliliuga laʻititi).

Pe a fa'aogaina vasega fa'amau i <a>elemene e fa'aaogaina e fa'aosoina ai galuega i totonu o le itulau (pei o le malepelepe o mea), nai lo le feso'ota'i i itulau fou po'o vaega i totonu o le itulau o lo'o i ai nei, e tatau ona tu'uina atu nei feso'ota'iga a role="button"e fa'ailoa lelei ai lo latou fa'amoemoe i tekinolosi fesoasoani e pei o le lau faitau mata.

So'oga
html
<a class="btn btn-primary" href="#" role="button">Link</a>
<button class="btn btn-primary" type="submit">Button</button>
<input class="btn btn-primary" type="button" value="Input">
<input class="btn btn-primary" type="submit" value="Submit">
<input class="btn btn-primary" type="reset" value="Reset">

Otootoga faamau

E mana'omia se fa'amau, ae le o lanu tetele o tua latou te aumaia? Suia vasega fa'aoga fa'aletonu i vasega .btn-outline-*e aveese uma ata ma lanu i luga o so'o se ki.

html
<button type="button" class="btn btn-outline-primary">Primary</button>
<button type="button" class="btn btn-outline-secondary">Secondary</button>
<button type="button" class="btn btn-outline-success">Success</button>
<button type="button" class="btn btn-outline-danger">Danger</button>
<button type="button" class="btn btn-outline-warning">Warning</button>
<button type="button" class="btn btn-outline-info">Info</button>
<button type="button" class="btn btn-outline-light">Light</button>
<button type="button" class="btn btn-outline-dark">Dark</button>
O nisi o sitaili fa'amau e fa'aogaina se lanu malamalama i luma, ma e tatau ona fa'aoga i luga o se ata pogisa ina ia lava le fa'atusatusaga.

Tele

Mana'o i fa'amau tetele pe la'ititi? Fa'aopoopo .btn-lgpe .btn-smmo isi lapopo'a.

html
<button type="button" class="btn btn-primary btn-lg">Large button</button>
<button type="button" class="btn btn-secondary btn-lg">Large button</button>
html
<button type="button" class="btn btn-primary btn-sm">Small button</button>
<button type="button" class="btn btn-secondary btn-sm">Small button</button>

E mafai fo'i ona e ta'avale lau lava laiga fa'aaganu'u fa'atasi ma fesuiaiga CSS:

html
<button type="button" class="btn btn-primary"
        style="--bs-btn-padding-y: .25rem; --bs-btn-padding-x: .5rem; --bs-btn-font-size: .75rem;">
  Custom button
</button>

Tulaga le atoatoa

Fa'apena fa'amau fa'agaoioi e ala i le fa'aopoopoina o le disableduiga boolean i so'o se <button>elemene. Ua fa'aoga fa'amau fa'aletonu pointer-events: none, e taofia ai le fa'agasolo ma tulaga fa'agaoioia mai le fa'aosoina.

html
<button type="button" class="btn btn-primary" disabled>Primary button</button>
<button type="button" class="btn btn-secondary" disabled>Button</button>
<button type="button" class="btn btn-outline-primary" disabled>Primary button</button>
<button type="button" class="btn btn-outline-secondary" disabled>Button</button>

O fa'amau fa'aletonu e fa'aaoga ai le <a>elemene e fai si 'ese'ese:

  • <a>e le lagolagoina le disableduiga, o lea e tatau ai ona e faaopoopo le .disabledvasega ina ia foliga mai e le atoatoa.
  • O nisi sitaili faauo i le lumana'i o lo'o i ai e fa'amalo uma pointer-eventsi fa'amau taula.
  • O fa'aoga fa'aletonu e <a>tatau ona aofia ai le aria-disabled="true"uiga e fa'ailoa ai le tulaga o le elemene i tekinolosi fesoasoani.
  • O fa'aoga fa'aletonu e <a> le tatau ona aofia ai le hrefuiga.
html
<a class="btn btn-primary disabled" role="button" aria-disabled="true">Primary link</a>
<a class="btn btn-secondary disabled" role="button" aria-disabled="true">Link</a>

Ina ia aofia ai mataupu e tatau ona e tausia ai le hrefuiga i luga o se so'oga fa'aletonu, .disablede fa'aaoga e le vasega pointer-events: nonee taumafai e fa'amalo le feso'ota'iga o <a>le s. Manatua o lenei CSS meatotino e leʻi faʻatulagaina mo HTML, ae o loʻo lagolagoina uma e suʻesuʻega faʻaonaponei. E le gata i lea, e oo lava i tagata su'esu'e o lo'o lagolagoina pointer-events: none, e tumau pea le le a'afiaina o le ta'avale keyboard, o lona uiga o tagata fa'aoga keyboard ma tagata fa'aoga fesoasoani tekonolosi o le a mafai lava ona fa'agaoioia nei so'oga. O lea ina ia saogalemu, e faaopoopo atu i le aria-disabled="true", ia aofia ai foi se tabindex="-1"uiga i luga o nei soʻotaga e taofia ai i latou mai le mauaina o le keyboard taulaʻi, ma faʻaaoga le JavaScript masani e faʻamalo uma ai a latou galuega.

html
<a href="#" class="btn btn-primary disabled" tabindex="-1" role="button" aria-disabled="true">Primary link</a>
<a href="#" class="btn btn-secondary disabled" tabindex="-1" role="button" aria-disabled="true">Link</a>

poloka poloka

Fausia fa'aputuga tali o le lautele-lautele, "poka poloka" pei o latou i totonu o le Bootstrap 4 fa'atasi ai ma se fa'afefiloi oa tatou fa'aaliga ma gap utilities. E ala i le fa'aogaina o mea fa'aoga ae le o fa'amau vasega fa'apitoa, e sili atu la tatou fa'atonuga i le va, fa'aogaina, ma le tali atu i amioga.

html
<div class="d-grid gap-2">
  <button class="btn btn-primary" type="button">Button</button>
  <button class="btn btn-primary" type="button">Button</button>
</div>

O iinei tatou te fatuina ai se fesuiaiga tali, amata i faʻamau faʻapipiʻi tuʻu saʻo seʻia oʻo i le mdvaeluaga, lea .d-md-blocke sui ai le .d-gridvasega, ma faʻaumatia ai le gap-2aoga. Toe sui lau su'esu'ega e va'ai ua suia.

html
<div class="d-grid gap-2 d-md-block">
  <button class="btn btn-primary" type="button">Button</button>
  <button class="btn btn-primary" type="button">Button</button>
</div>

E mafai ona e fetuutuuna'i le lautele o au poloka poloka ma vasega laina lautele laina laina. Mo se faʻataʻitaʻiga, mo le afa-lautele "poka poloka", faʻaaoga .col-6. Fa'atotonu fa'alava ma .mx-auto, fo'i.

html
<div class="d-grid gap-2 col-6 mx-auto">
  <button class="btn btn-primary" type="button">Button</button>
  <button class="btn btn-primary" type="button">Button</button>
</div>

E mafai ona fa'aoga mea fa'aopoopo e fetu'una'i ai le fa'aogaina o fa'amau pe a fa'ata'atia. O lea na matou faia ai la matou fa'ata'ita'iga tali muamua ma fa'aopoopo nisi mea fa'aoga felefele ma se fa'aoga pito i luga o le ki e fa'aoga sa'o ai fa'amau pe a le toe fa'aputuina.

html
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
  <button class="btn btn-primary me-md-2" type="button">Button</button>
  <button class="btn btn-primary" type="button">Button</button>
</div>

Fa'amau fa'amau

O le fa'amau fa'apipi'i e mafai ai ona e faia fa'amau fa'aoga faigofie i luga/taoti.

I le va'aia, o nei fa'amau fa'amau e tutusa lelei ma le pusa siaki fa'amau fa'amau . Ae ui i lea, e ese le faʻafeiloaʻi e ala i tekinolosi fesoasoani: o le a faʻasalalau le pusa siaki e le au faitau mataʻitusi e pei o le "siaki" / "le siakiina" (talu ai, e ui i o latou foliga vaaia, o loʻo avea pea ma pusa siaki), ae o nei kiki o le a faʻasalalau e pei o. “faamau”/“oomi le faamau”. O le filifiliga i le va o nei auala e lua o le a faʻalagolago i le ituaiga o kili o loʻo e fatuina, ma pe o le kili e talafeagai pe leai foi i tagata faʻaoga pe a faʻasalalauina o se pusa siaki poʻo se ki moni.

Togi setete

Fa'aopoopo data-bs-toggle="button"e sui le tulaga o se faamau active. Afai o lo'o e tosoina muamua se ki, e tatau ona e fa'aopoopo ma le lima le .activevasega ma aria-pressed="true" ia mautinoa o lo'o fa'asolo lelei i tekinolosi fesoasoani.

html
<button type="button" class="btn btn-primary" data-bs-toggle="button">Toggle button</button>
<button type="button" class="btn btn-primary active" data-bs-toggle="button" aria-pressed="true">Active toggle button</button>
<button type="button" class="btn btn-primary" disabled data-bs-toggle="button">Disabled toggle button</button>
html
<a href="#" class="btn btn-primary" role="button" data-bs-toggle="button">Toggle link</a>
<a href="#" class="btn btn-primary active" role="button" data-bs-toggle="button" aria-pressed="true">Active toggle link</a>
<a class="btn btn-primary disabled" aria-disabled="true" role="button" data-bs-toggle="button">Disabled toggle link</a>

Metotia

E mafai ona e fatuina se faʻataʻitaʻiga faʻatasi ma le fau mea faʻamau, mo se faʻataʻitaʻiga:

const bsButton = new bootstrap.Button('#myButton')
Metotia Fa'amatalaga
dispose Fa'aleaga le faamau o se elemene. (Ave'ese fa'amaumauga o lo'o teuina ile elemene DOM)
getInstance Metotia static lea e mafai ai ona e maua le faʻataʻitaʻiga faʻamau e fesoʻotaʻi ma se elemene DOM, e mafai ona e faʻaogaina e pei o lenei: bootstrap.Button.getInstance(element).
getOrCreateInstance Metotia static e toe faʻafoʻi ai se faʻataʻitaʻiga faʻamau e fesoʻotaʻi ma se elemene DOM poʻo le fatuina o se mea fou i le tulaga e leʻi amataina. E mafai ona e fa'aogaina fa'apenei: bootstrap.Button.getOrCreateInstance(element).
toggle Togi le tulaga tulei. Tu'u atu i le ki le foliga mai ua fa'agaoioia.

Mo se faataitaiga, e sui uma faamau

document.querySelectorAll('.btn').forEach(buttonElement => {
  const button = bootstrap.Button.getOrCreateInstance(buttonElement)
  button.toggle()
})

CSS

Fuafuaga

Fa'aopoopo i le v5.2.0

I le avea ai o se vaega o le faʻaogaina o suiga CSS a Bootstrap, o loʻo faʻaogaina nei e kuki le CSS faʻapitonuʻu i luga .btnmo le faʻaleleia o le taimi moni aganuʻu. O tau mo le CSS fesuiaiga e faʻatulagaina e ala i le Sass, o lea o loʻo lagolagoina pea le Sass customization.

  --#{$prefix}btn-padding-x: #{$btn-padding-x};
  --#{$prefix}btn-padding-y: #{$btn-padding-y};
  --#{$prefix}btn-font-family: #{$btn-font-family};
  @include rfs($btn-font-size, --#{$prefix}btn-font-size);
  --#{$prefix}btn-font-weight: #{$btn-font-weight};
  --#{$prefix}btn-line-height: #{$btn-line-height};
  --#{$prefix}btn-color: #{$body-color};
  --#{$prefix}btn-bg: transparent;
  --#{$prefix}btn-border-width: #{$btn-border-width};
  --#{$prefix}btn-border-color: transparent;
  --#{$prefix}btn-border-radius: #{$btn-border-radius};
  --#{$prefix}btn-hover-border-color: transparent;
  --#{$prefix}btn-box-shadow: #{$btn-box-shadow};
  --#{$prefix}btn-disabled-opacity: #{$btn-disabled-opacity};
  --#{$prefix}btn-focus-box-shadow: 0 0 0 #{$btn-focus-width} rgba(var(--#{$prefix}btn-focus-shadow-rgb), .5);
  

E .btn-*fa'afouina e vasega ta'itasi le suiga CSS talafeagai e fa'aitiitia ai tulafono fa'aopoopo CSS ma a tatou button-variant(), button-outline-variant(), ma button-size()mixins.

O se fa'ata'ita'iga lea o le fausiaina o se .btn-*vasega fa'aaganu'u fa'apitoa e pei ona tatou faia mo fa'amau fa'apitoa i a tatou fa'amaumauga e ala i le toe tu'uina atu o fesuiaiga CSS a Bootstrap ma le fa'afefiloi o tatou lava CSS ma Sass fesuiaiga.

.btn-bd-primary {
  --bs-btn-font-weight: 600;
  --bs-btn-color: var(--bs-white);
  --bs-btn-bg: var(--bd-violet);
  --bs-btn-border-color: var(--bd-violet);
  --bs-btn-border-radius: .5rem;
  --bs-btn-hover-color: var(--bs-white);
  --bs-btn-hover-bg: #{shade-color($bd-violet, 10%)};
  --bs-btn-hover-border-color: #{shade-color($bd-violet, 10%)};
  --bs-btn-focus-shadow-rgb: var(--bd-violet-rgb);
  --bs-btn-active-color: var(--bs-btn-hover-color);
  --bs-btn-active-bg: #{shade-color($bd-violet, 20%)};
  --bs-btn-active-border-color: #{shade-color($bd-violet, 20%)};
}

Sass fesuiaiga

$btn-padding-y:               $input-btn-padding-y;
$btn-padding-x:               $input-btn-padding-x;
$btn-font-family:             $input-btn-font-family;
$btn-font-size:               $input-btn-font-size;
$btn-line-height:             $input-btn-line-height;
$btn-white-space:             null; // Set to `nowrap` to prevent text wrapping

$btn-padding-y-sm:            $input-btn-padding-y-sm;
$btn-padding-x-sm:            $input-btn-padding-x-sm;
$btn-font-size-sm:            $input-btn-font-size-sm;

$btn-padding-y-lg:            $input-btn-padding-y-lg;
$btn-padding-x-lg:            $input-btn-padding-x-lg;
$btn-font-size-lg:            $input-btn-font-size-lg;

$btn-border-width:            $input-btn-border-width;

$btn-font-weight:             $font-weight-normal;
$btn-box-shadow:              inset 0 1px 0 rgba($white, .15), 0 1px 1px rgba($black, .075);
$btn-focus-width:             $input-btn-focus-width;
$btn-focus-box-shadow:        $input-btn-focus-box-shadow;
$btn-disabled-opacity:        .65;
$btn-active-box-shadow:       inset 0 3px 5px rgba($black, .125);

$btn-link-color:              var(--#{$prefix}link-color);
$btn-link-hover-color:        var(--#{$prefix}link-hover-color);
$btn-link-disabled-color:     $gray-600;

// Allows for customizing button radius independently from global border radius
$btn-border-radius:           $border-radius;
$btn-border-radius-sm:        $border-radius-sm;
$btn-border-radius-lg:        $border-radius-lg;

$btn-transition:              color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;

$btn-hover-bg-shade-amount:       15%;
$btn-hover-bg-tint-amount:        15%;
$btn-hover-border-shade-amount:   20%;
$btn-hover-border-tint-amount:    10%;
$btn-active-bg-shade-amount:      20%;
$btn-active-bg-tint-amount:       20%;
$btn-active-border-shade-amount:  25%;
$btn-active-border-tint-amount:   10%;

Sass mixins

E tolu fa'afefiloi mo fa'amau: fa'afefiloi fa'afefiloi fa'avasegaga fa'amau ma fa'amau (fa'atatau uma i le $theme-colors), fa'atasi ai ma le fa'afefiloi o lapo'a fa'amau.

@mixin button-variant(
  $background,
  $border,
  $color: color-contrast($background),
  $hover-background: if($color == $color-contrast-light, shade-color($background, $btn-hover-bg-shade-amount), tint-color($background, $btn-hover-bg-tint-amount)),
  $hover-border: if($color == $color-contrast-light, shade-color($border, $btn-hover-border-shade-amount), tint-color($border, $btn-hover-border-tint-amount)),
  $hover-color: color-contrast($hover-background),
  $active-background: if($color == $color-contrast-light, shade-color($background, $btn-active-bg-shade-amount), tint-color($background, $btn-active-bg-tint-amount)),
  $active-border: if($color == $color-contrast-light, shade-color($border, $btn-active-border-shade-amount), tint-color($border, $btn-active-border-tint-amount)),
  $active-color: color-contrast($active-background),
  $disabled-background: $background,
  $disabled-border: $border,
  $disabled-color: color-contrast($disabled-background)
) {
  --#{$prefix}btn-color: #{$color};
  --#{$prefix}btn-bg: #{$background};
  --#{$prefix}btn-border-color: #{$border};
  --#{$prefix}btn-hover-color: #{$hover-color};
  --#{$prefix}btn-hover-bg: #{$hover-background};
  --#{$prefix}btn-hover-border-color: #{$hover-border};
  --#{$prefix}btn-focus-shadow-rgb: #{to-rgb(mix($color, $border, 15%))};
  --#{$prefix}btn-active-color: #{$active-color};
  --#{$prefix}btn-active-bg: #{$active-background};
  --#{$prefix}btn-active-border-color: #{$active-border};
  --#{$prefix}btn-active-shadow: #{$btn-active-box-shadow};
  --#{$prefix}btn-disabled-color: #{$disabled-color};
  --#{$prefix}btn-disabled-bg: #{$disabled-background};
  --#{$prefix}btn-disabled-border-color: #{$disabled-border};
}
@mixin button-outline-variant(
  $color,
  $color-hover: color-contrast($color),
  $active-background: $color,
  $active-border: $color,
  $active-color: color-contrast($active-background)
) {
  --#{$prefix}btn-color: #{$color};
  --#{$prefix}btn-border-color: #{$color};
  --#{$prefix}btn-hover-color: #{$color-hover};
  --#{$prefix}btn-hover-bg: #{$active-background};
  --#{$prefix}btn-hover-border-color: #{$active-border};
  --#{$prefix}btn-focus-shadow-rgb: #{to-rgb($color)};
  --#{$prefix}btn-active-color: #{$active-color};
  --#{$prefix}btn-active-bg: #{$active-background};
  --#{$prefix}btn-active-border-color: #{$active-border};
  --#{$prefix}btn-active-shadow: #{$btn-active-box-shadow};
  --#{$prefix}btn-disabled-color: #{$color};
  --#{$prefix}btn-disabled-bg: transparent;
  --#{$prefix}btn-disabled-border-color: #{$color};
  --#{$prefix}gradient: none;
}
@mixin button-size($padding-y, $padding-x, $font-size, $border-radius) {
  --#{$prefix}btn-padding-y: #{$padding-y};
  --#{$prefix}btn-padding-x: #{$padding-x};
  @include rfs($font-size, --#{$prefix}btn-font-size);
  --#{$prefix}btn-border-radius: #{$border-radius};
}

Sass matasele

Fa'aliliuga fa'amau (mo fa'amau masani ma fa'amaufa'ailoga) fa'aoga a latou fa'afefiloi fa'atasi ma la tatou $theme-colorsfa'afanua e fa'atupuina ai vasega fa'aliliu i scss/_buttons.scss.

@each $color, $value in $theme-colors {
  .btn-#{$color} {
    @if $color == "light" {
      @include button-variant(
        $value,
        $value,
        $hover-background: shade-color($value, $btn-hover-bg-shade-amount),
        $hover-border: shade-color($value, $btn-hover-border-shade-amount),
        $active-background: shade-color($value, $btn-active-bg-shade-amount),
        $active-border: shade-color($value, $btn-active-border-shade-amount)
      );
    } @else if $color == "dark" {
      @include button-variant(
        $value,
        $value,
        $hover-background: tint-color($value, $btn-hover-bg-tint-amount),
        $hover-border: tint-color($value, $btn-hover-border-tint-amount),
        $active-background: tint-color($value, $btn-active-bg-tint-amount),
        $active-border: tint-color($value, $btn-active-border-tint-amount)
      );
    } @else {
      @include button-variant($value, $value);
    }
  }
}

@each $color, $value in $theme-colors {
  .btn-outline-#{$color} {
    @include button-outline-variant($value);
  }
}