Rekọja si akoonu akọkọ Rekọja si lilọ kiri awọn docs
Check
in English

Ìfilélẹ

Fun awọn fọọmu rẹ diẹ ninu eto-lati laini si petele si awọn imuse akoj aṣa—pẹlu awọn aṣayan iṣeto fọọmu wa.

Awọn fọọmu

Gbogbo ẹgbẹ ti awọn aaye fọọmu yẹ ki o gbe inu <form>eroja kan. Bootstrap pese ko si iselona aiyipada fun <form>eroja, ṣugbọn awọn ẹya ẹrọ aṣawakiri ti o lagbara wa ti o pese nipasẹ aiyipada.

  • Tuntun si awọn fọọmu aṣawakiri bi? Gbero atunwo awọn iwe aṣẹ fọọmu MDN fun awotẹlẹ ati atokọ pipe ti awọn abuda to wa.
  • <button>s laarin <form>aiyipada si type="submit", nitorina gbiyanju lati wa ni pato ati nigbagbogbo pẹlu kan type.

Niwọn igba ti Bootstrap ti kan display: blockati width: 100%si gbogbo awọn iṣakoso fọọmu wa, awọn fọọmu yoo jẹ akopọ aiyipada ni inaro. Awọn afikun awọn kilasi le ṣee lo lati yatọ si ipilẹ yii lori ipilẹ-fọọmu kan.

Awọn ohun elo

Awọn ohun elo ala -ilẹ jẹ ọna ti o rọrun julọ lati ṣafikun eto diẹ si awọn fọọmu. Wọn pese akojọpọ ipilẹ ti awọn aami, awọn idari, ọrọ fọọmu iyan, ati fifiranṣẹ afọwọsi fọọmu. A ṣe iṣeduro duro si margin-bottomawọn ohun elo, ati lilo itọsọna kan jakejado fọọmu fun aitasera.

Lero ọfẹ lati kọ awọn fọọmu rẹ bi o ṣe fẹ, pẹlu <fieldset>s, <div>s, tabi fere eyikeyi nkan miiran.

html
<div class="mb-3">
  <label for="formGroupExampleInput" class="form-label">Example label</label>
  <input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input placeholder">
</div>
<div class="mb-3">
  <label for="formGroupExampleInput2" class="form-label">Another label</label>
  <input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input placeholder">
</div>

Akoj fọọmu

Awọn fọọmu eka diẹ sii ni a le kọ nipa lilo awọn kilasi akoj wa. Lo iwọnyi fun awọn ipilẹ fọọmu ti o nilo awọn ọwọn pupọ, awọn iwọn ti o yatọ, ati awọn aṣayan titete afikun. Nilo $enable-grid-classesoniyipada Sass lati muu ṣiṣẹ (lori nipasẹ aiyipada).

html
<div class="row">
  <div class="col">
    <input type="text" class="form-control" placeholder="First name" aria-label="First name">
  </div>
  <div class="col">
    <input type="text" class="form-control" placeholder="Last name" aria-label="Last name">
  </div>
</div>

Awọn gutters

Nipa fifi awọn kilasi modifier gotter kun , o le ni iṣakoso lori iwọn gọta ninu bakanna opopo bi itọsọna dina. Paapaa nilo $enable-grid-classesoniyipada Sass lati mu ṣiṣẹ (lori nipasẹ aiyipada).

html
<div class="row g-3">
  <div class="col">
    <input type="text" class="form-control" placeholder="First name" aria-label="First name">
  </div>
  <div class="col">
    <input type="text" class="form-control" placeholder="Last name" aria-label="Last name">
  </div>
</div>

Awọn ipalemo eka diẹ sii tun le ṣẹda pẹlu eto akoj.

html
<form class="row g-3">
  <div class="col-md-6">
    <label for="inputEmail4" class="form-label">Email</label>
    <input type="email" class="form-control" id="inputEmail4">
  </div>
  <div class="col-md-6">
    <label for="inputPassword4" class="form-label">Password</label>
    <input type="password" class="form-control" id="inputPassword4">
  </div>
  <div class="col-12">
    <label for="inputAddress" class="form-label">Address</label>
    <input type="text" class="form-control" id="inputAddress" placeholder="1234 Main St">
  </div>
  <div class="col-12">
    <label for="inputAddress2" class="form-label">Address 2</label>
    <input type="text" class="form-control" id="inputAddress2" placeholder="Apartment, studio, or floor">
  </div>
  <div class="col-md-6">
    <label for="inputCity" class="form-label">City</label>
    <input type="text" class="form-control" id="inputCity">
  </div>
  <div class="col-md-4">
    <label for="inputState" class="form-label">State</label>
    <select id="inputState" class="form-select">
      <option selected>Choose...</option>
      <option>...</option>
    </select>
  </div>
  <div class="col-md-2">
    <label for="inputZip" class="form-label">Zip</label>
    <input type="text" class="form-control" id="inputZip">
  </div>
  <div class="col-12">
    <div class="form-check">
      <input class="form-check-input" type="checkbox" id="gridCheck">
      <label class="form-check-label" for="gridCheck">
        Check me out
      </label>
    </div>
  </div>
  <div class="col-12">
    <button type="submit" class="btn btn-primary">Sign in</button>
  </div>
</form>

Fọọmu petele

Ṣẹda awọn fọọmu petele pẹlu akoj nipa fifi .rowkilasi kun lati ṣẹda awọn ẹgbẹ ati lilo awọn .col-*-*kilasi lati pato iwọn awọn aami ati awọn idari rẹ. Rii daju lati ṣafikun .col-form-labelrẹ<label> s rẹ daradara nitorina wọn wa ni inaro pẹlu awọn idari fọọmu ti o somọ.

Ni awọn igba miiran, o le nilo lati lo ala tabi awọn ohun elo padding lati ṣẹda titete pipe ti o nilo. Fun apẹẹrẹ, a ti yọkuro padding-toplori aami awọn igbewọle redio tolera wa lati ṣe deede ipilẹ ọrọ dara julọ.

Redio
html
<form>
  <div class="row mb-3">
    <label for="inputEmail3" class="col-sm-2 col-form-label">Email</label>
    <div class="col-sm-10">
      <input type="email" class="form-control" id="inputEmail3">
    </div>
  </div>
  <div class="row mb-3">
    <label for="inputPassword3" class="col-sm-2 col-form-label">Password</label>
    <div class="col-sm-10">
      <input type="password" class="form-control" id="inputPassword3">
    </div>
  </div>
  <fieldset class="row mb-3">
    <legend class="col-form-label col-sm-2 pt-0">Radios</legend>
    <div class="col-sm-10">
      <div class="form-check">
        <input class="form-check-input" type="radio" name="gridRadios" id="gridRadios1" value="option1" checked>
        <label class="form-check-label" for="gridRadios1">
          First radio
        </label>
      </div>
      <div class="form-check">
        <input class="form-check-input" type="radio" name="gridRadios" id="gridRadios2" value="option2">
        <label class="form-check-label" for="gridRadios2">
          Second radio
        </label>
      </div>
      <div class="form-check disabled">
        <input class="form-check-input" type="radio" name="gridRadios" id="gridRadios3" value="option3" disabled>
        <label class="form-check-label" for="gridRadios3">
          Third disabled radio
        </label>
      </div>
    </div>
  </fieldset>
  <div class="row mb-3">
    <div class="col-sm-10 offset-sm-2">
      <div class="form-check">
        <input class="form-check-input" type="checkbox" id="gridCheck1">
        <label class="form-check-label" for="gridCheck1">
          Example checkbox
        </label>
      </div>
    </div>
  </div>
  <button type="submit" class="btn btn-primary">Sign in</button>
</form>

Petele fọọmu aami iwọn

Rii daju lati lo .col-form-label-smtabi .col-form-label-lgsi awọn <label>s tabi <legend>s rẹ lati tẹle iwọn .form-control-lgati deede .form-control-sm.

html
<div class="row mb-3">
  <label for="colFormLabelSm" class="col-sm-2 col-form-label col-form-label-sm">Email</label>
  <div class="col-sm-10">
    <input type="email" class="form-control form-control-sm" id="colFormLabelSm" placeholder="col-form-label-sm">
  </div>
</div>
<div class="row mb-3">
  <label for="colFormLabel" class="col-sm-2 col-form-label">Email</label>
  <div class="col-sm-10">
    <input type="email" class="form-control" id="colFormLabel" placeholder="col-form-label">
  </div>
</div>
<div class="row">
  <label for="colFormLabelLg" class="col-sm-2 col-form-label col-form-label-lg">Email</label>
  <div class="col-sm-10">
    <input type="email" class="form-control form-control-lg" id="colFormLabelLg" placeholder="col-form-label-lg">
  </div>
</div>

Iwọn ti ọwọn

Gẹgẹbi a ṣe han ninu awọn apẹẹrẹ ti tẹlẹ, eto akoj wa gba ọ laaye lati gbe nọmba eyikeyi ti .cols laarin faili kan .row. Wọn yoo pin iwọn to wa ni dọgbadọgba laarin wọn. O tun le mu ipin kan ti awọn ọwọn rẹ lati gba aaye diẹ sii tabi kere si, lakoko ti awọn ti o ku ni o .colpin bakanna pẹlu awọn kilasi iwe kan pato bi .col-sm-7.

html
<div class="row g-3">
  <div class="col-sm-7">
    <input type="text" class="form-control" placeholder="City" aria-label="City">
  </div>
  <div class="col-sm">
    <input type="text" class="form-control" placeholder="State" aria-label="State">
  </div>
  <div class="col-sm">
    <input type="text" class="form-control" placeholder="Zip" aria-label="Zip">
  </div>
</div>

Titobi aifọwọyi

Apẹẹrẹ ti o wa ni isalẹ nlo ohun elo flexbox lati aarin awọn akoonu inu inaro ati awọn iyipada .colsi .col-autoki awọn ọwọn rẹ nikan gba aaye pupọ bi o ṣe nilo. Fi ọna miiran, awọn iwọn ọwọn funrararẹ da lori awọn akoonu.

@
html
<form class="row gy-2 gx-3 align-items-center">
  <div class="col-auto">
    <label class="visually-hidden" for="autoSizingInput">Name</label>
    <input type="text" class="form-control" id="autoSizingInput" placeholder="Jane Doe">
  </div>
  <div class="col-auto">
    <label class="visually-hidden" for="autoSizingInputGroup">Username</label>
    <div class="input-group">
      <div class="input-group-text">@</div>
      <input type="text" class="form-control" id="autoSizingInputGroup" placeholder="Username">
    </div>
  </div>
  <div class="col-auto">
    <label class="visually-hidden" for="autoSizingSelect">Preference</label>
    <select class="form-select" id="autoSizingSelect">
      <option selected>Choose...</option>
      <option value="1">One</option>
      <option value="2">Two</option>
      <option value="3">Three</option>
    </select>
  </div>
  <div class="col-auto">
    <div class="form-check">
      <input class="form-check-input" type="checkbox" id="autoSizingCheck">
      <label class="form-check-label" for="autoSizingCheck">
        Remember me
      </label>
    </div>
  </div>
  <div class="col-auto">
    <button type="submit" class="btn btn-primary">Submit</button>
  </div>
</form>

Lẹhinna o le tun ṣe atunṣe lẹẹkan si pẹlu awọn kilasi iwe-iwọn kan pato.

@
html
<form class="row gx-3 gy-2 align-items-center">
  <div class="col-sm-3">
    <label class="visually-hidden" for="specificSizeInputName">Name</label>
    <input type="text" class="form-control" id="specificSizeInputName" placeholder="Jane Doe">
  </div>
  <div class="col-sm-3">
    <label class="visually-hidden" for="specificSizeInputGroupUsername">Username</label>
    <div class="input-group">
      <div class="input-group-text">@</div>
      <input type="text" class="form-control" id="specificSizeInputGroupUsername" placeholder="Username">
    </div>
  </div>
  <div class="col-sm-3">
    <label class="visually-hidden" for="specificSizeSelect">Preference</label>
    <select class="form-select" id="specificSizeSelect">
      <option selected>Choose...</option>
      <option value="1">One</option>
      <option value="2">Two</option>
      <option value="3">Three</option>
    </select>
  </div>
  <div class="col-auto">
    <div class="form-check">
      <input class="form-check-input" type="checkbox" id="autoSizingCheck2">
      <label class="form-check-label" for="autoSizingCheck2">
        Remember me
      </label>
    </div>
  </div>
  <div class="col-auto">
    <button type="submit" class="btn btn-primary">Submit</button>
  </div>
</form>

Awọn fọọmu inline

Lo awọn .row-cols-*kilasi lati ṣẹda awọn ipilẹ petele idahun. Nipa fifi awọn kilasi modifier gọta kun , a yoo ni awọn gutters ni petele ati awọn itọnisọna inaro. Lori awọn ibudo iwo alagbeka dín, .col-12iranlọwọ ṣe akopọ awọn iṣakoso fọọmu ati diẹ sii. Awọn .align-items-centeraligns awọn eroja fọọmu si aarin, ṣiṣe awọn .form-checkaligning daradara.

@
html
<form class="row row-cols-lg-auto g-3 align-items-center">
  <div class="col-12">
    <label class="visually-hidden" for="inlineFormInputGroupUsername">Username</label>
    <div class="input-group">
      <div class="input-group-text">@</div>
      <input type="text" class="form-control" id="inlineFormInputGroupUsername" placeholder="Username">
    </div>
  </div>

  <div class="col-12">
    <label class="visually-hidden" for="inlineFormSelectPref">Preference</label>
    <select class="form-select" id="inlineFormSelectPref">
      <option selected>Choose...</option>
      <option value="1">One</option>
      <option value="2">Two</option>
      <option value="3">Three</option>
    </select>
  </div>

  <div class="col-12">
    <div class="form-check">
      <input class="form-check-input" type="checkbox" id="inlineFormCheck">
      <label class="form-check-label" for="inlineFormCheck">
        Remember me
      </label>
    </div>
  </div>

  <div class="col-12">
    <button type="submit" class="btn btn-primary">Submit</button>
  </div>
</form>