Tīpoka ki te ihirangi matua Tīpoka ki te whakaterenga tuhinga
in English

Patene

Whakamahia nga momo patene ritenga a Bootstrap mo nga mahi i roto i nga puka, nga korero, me etahi atu me te tautoko mo nga rahi maha, ahua, me etahi atu.

Tauira

Kei roto i te Bootstrap te maha o nga momo patene kua tautuhia, e mahi ana ia tangata ki tana ake kaupapa korero, me etahi taapiri ka maka ki roto kia kaha ake te whakahaere.

<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>
Te kawe i te tikanga ki nga hangarau awhina

Ko te whakamahi i te tae ki te taapiri i te tikanga he tohu tirohanga noa iho, kaore e tukuna ki nga kaiwhakamahi hangarau awhina - penei i nga kaipanui mata. Me mohio kei te kitea nga korero e tohuhia ana e te tae mai i te ihirangi ake (hei tauira, te tuhinga ka kitea), ka whakaurua ranei ma etahi atu huarahi, penei i etahi atu tuhinga huna ki te .visually-hiddenakomanga.

Monokia te takai kuputuhi

Ki te kore koe e pirangi kia takai te kupu patene, ka taea e koe te taapiri i te .text-nowrapkaraehe ki te paatene. I roto i te Sass, ka taea e koe te tautuhi $btn-white-space: nowrapki te whakakore i te takai kuputuhi mo ia paatene.

Nga tohu paatene

Kua .btnhoahoatia nga karaehe hei whakamahi me te <button>huānga. Heoi, ka taea hoki e koe te whakamahi i enei karaehe ki runga , ki nga huānga <a>ranei <input>(ahakoa he rereke te ahua o etahi kaitirotiro).

Ina whakamahi i nga karaehe patene i runga i <a>nga huānga e whakamahia ana ki te whakaoho i te mahi-a-wharangi (penei i te tiango ihirangi), kaua ki te hono ki nga wharangi hou, ki nga waahanga ranei o te wharangi o naianei, me hoatu enei hononga ki te role="button"kawe tika i o raatau kaupapa ki nga hangarau awhina penei i te kaipānui mata.

Hononga
<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">

Patene Whakahuahua

Kei te hiahia te paatene, engari ehara i nga tae papamuri nui e mauria mai ana? Whakakapihia nga karaehe whakarereke taunoa me nga .btn-outline-*mea hei tango i nga whakaahua papamuri me nga tae katoa i runga i tetahi paatene.

<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>
Ko etahi o nga momo patene e whakamahi ana i te tae o mua ahua marama, a me whakamahi i runga i te papamuri pouri kia pai ai te rereke.

Rahi

Kei te pirangi koe ki nga paatene nui, iti ake ranei? Tāpirihia mo etahi atu rahinga .btn-lgranei ..btn-sm

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

Te ahua haua

Kia hohekore nga paatene ma te taapiri i te disabledhuanga boolean ki tetahi <button>huānga. Kua tonohia nga patene monokia pointer-events: noneki te aukati i te whakaparo me nga ahuatanga hohe kia kore e puta.

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

<a>He rereke te ahua o nga patene monoa e whakamahi ana i te huānga:

  • <a>s kore e tautoko i te disabledhuanga, no reira me tapiri e koe te .disabledkaraehe kia kore ai e kitea te haua.
  • Ko etahi o nga momo ahua pai mo nga ra kei te heke mai hei whakakore i nga mea katoa pointer-eventsi runga i nga paatene punga.
  • Me whakauru nga patene haua i te aria-disabled="true"huanga hei tohu i te ahua o te huānga ki nga hangarau awhina.
<a href="#" class="btn btn-primary btn-lg disabled" tabindex="-1" role="button" aria-disabled="true">Primary link</a>
<a href="#" class="btn btn-secondary btn-lg disabled" tabindex="-1" role="button" aria-disabled="true">Link</a>

Ka .disabledwhakamahia e te karaehe pointer-events: noneki te ngana ki te whakakore i te taumahinga hono o <a>s, engari kaore ano kia paerewatia taua taonga CSS. I tua atu, ahakoa i roto i nga kaitirotiro e tautoko pointer-events: noneana, kaore e pa ana te whakatere papapātuhi, ko te tikanga ka taea tonu e nga kaiwhakamahi papapātuhi me nga kaiwhakamahi o nga hangarau awhina te whakahohe i enei hononga. Na kia noho haumaru, hei taapiri atu ki te aria-disabled="true", whakauruhia he tabindex="-1"huanga ki runga i enei hononga kia kore ai ratou e whiwhi arotahi papapātuhi, me te whakamahi i te JavaScript ritenga ki te whakakore i o raatau mahi.

Patene poraka

Waihangahia he puranga urupare o te whanui-katoa, "patene paraka" pera i era i Bootstrap 4 me te whakakotahitanga o a maatau taputapu whakaatu me te waatea. Ma te whakamahi i nga taputapu hei utu mo nga karaehe patene, ka nui ake te mana whakahaere mo te mokowā, te tirohanga, me nga whanonga aro.

<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>

I konei ka waihangahia e matou he rereketanga urupare, ka timata mai i nga patene poutū tae noa ki te mdwaahi pakaru, ka .d-md-blockwhakakapi i te .d-gridakomanga, na reira ka whakakorehia te gap-2whaipainga. Whakanuia te rahi o to kaitirotiro kia kitea e huri ana.

<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>

Ka taea e koe te whakatika i te whanui o o paatene paraka me nga karaehe whanui poupae matiti. Hei tauira, mo te hawhe-whanui "patene poraka", whakamahia .col-6. Whakawaenga whakapae ki te .mx-auto, rawa.

<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>

Ka taea te whakamahi i etahi atu taputapu hei whakatika i te tirohanga o nga paatene ina whakapae. I konei kua tangohia e matou ta matou tauira urupare o mua me te taapiri i etahi taputapu ngawari me tetahi taputapu tawhē i runga i te paatene ki te whakatika tika i nga paatene ka kore e tapae.

<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>

Pātene monomai

Ma te paatene mono ka taea e koe te hanga i nga paatene takahuri ngawari.

Ki te titiro, he rite enei patene takahuri ki nga paatene takahuri pouakataki . Heoi, he rereke te kawe mai e nga hangarau awhina: ka panuihia nga takahuri pouakataki e nga kaipanui mata he "tirohia"/"kaore i takina" (i te mea, ahakoa te ahua, he pouakataki tonu), engari ko enei paatene takahuri ka panuitia hei “pātene”/“pātene pēhi”. Ko te whiriwhiri i waenga i enei huarahi e rua ka whakawhirinaki ki te momo takahuri e hangaia ana e koe, a mena ka whai whakaaro te takahuri ki nga kaiwhakamahi ina panuitia hei pouakataki, hei paatene tuuturu ranei.

Takahuri āhua

Tāpirihia data-bs-toggle="button"hei takahuri i te activeahua o te paatene. Mēnā kei te takahuri i mua i te paatene, me taapiri a ringa koe i te .activeakomanga me aria-pressed="true" te whakarite kia tika te kawe ki nga hangarau awhina.

<button type="button" class="btn btn-primary" data-bs-toggle="button" autocomplete="off">Toggle button</button>
<button type="button" class="btn btn-primary active" data-bs-toggle="button" autocomplete="off" aria-pressed="true">Active toggle button</button>
<button type="button" class="btn btn-primary" disabled data-bs-toggle="button" autocomplete="off">Disabled toggle button</button>
<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 href="#" class="btn btn-primary disabled" tabindex="-1" aria-disabled="true" role="button" data-bs-toggle="button">Disabled toggle link</a>

Nga tikanga

Ka taea e koe te hanga i tetahi tauira paatene me te kaihanga paatene, hei tauira:

var button = document.getElementById('myButton')
var bsButton = new bootstrap.Button(button)
Tikanga Whakaahuatanga
toggle Ka takahuri te ahua pana. Ka hoatu ki te paatene te ahua kua whakahohehia.
dispose Ka whakakore i te paatene o te huānga. (Tangohia ai nga raraunga rongoa i te huānga DOM)
getInstance Tikanga pateko e taea ai e koe te tiki i te tauira paatene e hono ana ki tetahi huānga DOM, ka taea e koe te whakamahi penei:bootstrap.Button.getInstance(element)
getOrCreateInstance Aratuka pateko e whakahoki mai ana i tetahi tauira patene e hono ana ki tetahi huānga DOM, ki te hanga i tetahi mea hou mena kaore i arawhitia. Ka taea e koe te whakamahi penei:bootstrap.Button.getOrCreateInstance(element)

Hei tauira, ki te takahuri i nga paatene katoa

var buttons = document.querySelectorAll('.btn')
buttons.forEach(function (button) {
  var button = new bootstrap.Button(button)
  button.toggle()
})

Sass

Taurangi

$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:              $link-color;
$btn-link-hover-color:        $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%;

Whakaranu

E toru nga whakaurunga mo nga patene: patene me te patene whakahuahua whakarakei rereke (e rua i runga i te $theme-colors), me te ranunga rahi o te paatene.

@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)
) {
  color: $color;
  @include gradient-bg($background);
  border-color: $border;
  @include box-shadow($btn-box-shadow);

  &:hover {
    color: $hover-color;
    @include gradient-bg($hover-background);
    border-color: $hover-border;
  }

  .btn-check:focus + &,
  &:focus {
    color: $hover-color;
    @include gradient-bg($hover-background);
    border-color: $hover-border;
    @if $enable-shadows {
      @include box-shadow($btn-box-shadow, 0 0 0 $btn-focus-width rgba(mix($color, $border, 15%), .5));
    } @else {
      // Avoid using mixin so we can pass custom focus shadow properly
      box-shadow: 0 0 0 $btn-focus-width rgba(mix($color, $border, 15%), .5);
    }
  }

  .btn-check:checked + &,
  .btn-check:active + &,
  &:active,
  &.active,
  .show > &.dropdown-toggle {
    color: $active-color;
    background-color: $active-background;
    // Remove CSS gradients if they're enabled
    background-image: if($enable-gradients, none, null);
    border-color: $active-border;

    &:focus {
      @if $enable-shadows {
        @include box-shadow($btn-active-box-shadow, 0 0 0 $btn-focus-width rgba(mix($color, $border, 15%), .5));
      } @else {
        // Avoid using mixin so we can pass custom focus shadow properly
        box-shadow: 0 0 0 $btn-focus-width rgba(mix($color, $border, 15%), .5);
      }
    }
  }

  &:disabled,
  &.disabled {
    color: $disabled-color;
    background-color: $disabled-background;
    // Remove CSS gradients if they're enabled
    background-image: if($enable-gradients, none, null);
    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)
) {
  color: $color;
  border-color: $color;

  &:hover {
    color: $color-hover;
    background-color: $active-background;
    border-color: $active-border;
  }

  .btn-check:focus + &,
  &:focus {
    box-shadow: 0 0 0 $btn-focus-width rgba($color, .5);
  }

  .btn-check:checked + &,
  .btn-check:active + &,
  &:active,
  &.active,
  &.dropdown-toggle.show {
    color: $active-color;
    background-color: $active-background;
    border-color: $active-border;

    &:focus {
      @if $enable-shadows {
        @include box-shadow($btn-active-box-shadow, 0 0 0 $btn-focus-width rgba($color, .5));
      } @else {
        // Avoid using mixin so we can pass custom focus shadow properly
        box-shadow: 0 0 0 $btn-focus-width rgba($color, .5);
      }
    }
  }

  &:disabled,
  &.disabled {
    color: $color;
    background-color: transparent;
  }
}
@mixin button-size($padding-y, $padding-x, $font-size, $border-radius) {
  padding: $padding-y $padding-x;
  @include font-size($font-size);
  // Manually declare to provide an override to the browser default
  @include border-radius($border-radius, 0);
}

Koropiko

Ko nga rereke o te paatene (mo nga paatene auau me te whakahuahua) ka whakamahi i o raatau whakaurunga me to maatau $theme-colorsmapi hei whakaputa i nga karaehe whakarereke i roto scss/_buttons.scss.

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

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