Rach gu prìomh shusbaint Air adhart gu seòladh docs

Thoir beagan structair dha na foirmean agad - bho in-loidhne gu còmhnard gu buileachadh clèithe àbhaisteach - leis na roghainnean cruth foirm againn.

Foirmean

Bu chòir a h-uile buidheann de raointean cruth a bhith a’ fuireach ann an <form>eileamaid. Chan eil Bootstrap a’ toirt seachad stoidhle bunaiteach airson an <form>eileamaid, ach tha cuid de fheartan brabhsair cumhachdach ann a tha air an toirt seachad gu bunaiteach.

  • Ùr do fhoirmean brabhsair? Beachdaich air ath-sgrùdadh a dhèanamh air na docaichean foirm MDN airson sealladh farsaing agus liosta iomlan de na buadhan a tha rim faighinn.
  • <button>s taobh a-staigh <form>bunait bunaiteach gu type="submit", mar sin feuch ri bhith sònraichte agus cuir a-steach faidhle type.
  • Faodaidh tu a h-uile eileamaid foirm taobh a-staigh foirm a dhì-cheadachadh leis a’ disabledfheart air an <form>.

Leis gu bheil Bootstrap a’ buntainn display: blockagus width: 100%ri cha mhòr a h-uile smachd foirm againn, bidh foirmean a’ cruachadh gu dìreach. Faodar clasaichean a bharrachd a chleachdadh gus an cruth seo atharrachadh a rèir gach foirm.

Goireasan

Is e goireasan iomaill an dòigh as fhasa beagan structar a chur ri foirmean. Bidh iad a’ toirt seachad cruinneachadh bunaiteach de bhileagan, smachdan, teacsa cruth roghainneil, agus teachdaireachdan dearbhaidh cruth. Tha sinn a 'moladh a bhith a' cumail ri margin-bottomgoireasan, agus a 'cleachdadh aon stiùireadh air feadh an fhoirm airson cunbhalachd.

Faodaidh tu na foirmean agad a thogail ge bith dè as toil leat, le <fieldset>s, <div>s, no cha mhòr eileamaid sam bith eile.

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

Foirm grid

Faodar foirmean nas iom-fhillte a thogail a’ cleachdadh ar clasaichean clèithe. Cleachd iad sin airson cruth cruth a dh’ fheumas grunn cholbhan, leudan eadar-dhealaichte, agus roghainnean co-thaobhadh a bharrachd. Feumaidh an $enable-grid-classescaochladair Sass a bhith air a chomasachadh (air adhart gu bunaiteach).

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

cutairean

Le bhith a’ cur a-steach clasaichean mion-atharrachaidh cutairean , faodaidh smachd a bhith agad air leud an gutter a bharrachd air an loidhne a-staigh ri stiùireadh bloca. Cuideachd feumar an $enable-grid-classescaochladair Sass a bhith air a chomasachadh (air adhart gu bunaiteach).

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

Faodar dealbhadh nas iom-fhillte a chruthachadh cuideachd leis an t-siostam clèithe.

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

Foirm chòmhnard

Cruthaich foirmean còmhnard leis a’ ghriod le bhith a’ cur a’ .rowchlas ris gus buidhnean a chruthachadh agus a’ cleachdadh nan .col-*-*clasaichean gus leud do bhileagan is do smachdan a shònrachadh. Dèan cinnteach gun cuir .col-form-labelthu ris na s agad <label>cuideachd gus am bi iad stèidhichte gu dìreach leis na smachdan cruth co-cheangailte riutha.

Aig amannan, is dòcha gum feum thu goireasan iomaill no pleadhaig a chleachdadh gus an co-thaobhadh foirfe sin a tha a dhìth ort a chruthachadh. Mar eisimpleir, tha sinn air an padding-topleubail cuir a-steach rèidio cruachan againn a thoirt air falbh gus bun-loidhne an teacsa a cho-thaobhadh nas fheàrr.

Rèidiothan
<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>

Meud leubail cruth còmhnard

Dèan cinnteach gun cleachd thu .col-form-label-smno ris an fheadhainn agad fhèin gus meud agus ..col-form-label-lg<label><legend>.form-control-lg.form-control-sm

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

Meud colbh

Mar a chithear anns na h-eisimpleirean roimhe seo, leigidh an siostam clèithe againn leat àireamh sam bith de .cols a chuir taobh a-staigh faidhle .row. Roinnidh iad an leud a tha ri fhaighinn gu cothromach eatorra. Faodaidh tu cuideachd fo-sheata de na colbhan agad a thaghadh gus barrachd no nas lugha de rùm a ghabhail, fhad ‘ .cols a bhios an còrr a’ roinn a ’chòrr gu co-ionann, le clasaichean colbh sònraichte mar .col-sm-7.

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

Meudachadh fèin-ghluasadach

Tha an eisimpleir gu h-ìosal a’ cleachdadh goireas flexbox gus susbaint a mheadhanachadh gu dìreach agus atharraichean .colair .col-autogus nach bi na colbhan agad a’ gabhail ach na h-uimhir de dh’ àite ’s a dh’ fheumar. Cuir dòigh eile, meudan a’ cholbh fhèin stèidhichte air na th’ ann.

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

Faodaidh tu an uairsin ath-aithris sin a-rithist le clasaichean colbh a tha sònraichte do mheud.

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

Foirmean in-loidhne

Cleachd na .row-cols-*clasaichean gus dealbhadh còmhnard freagairteach a chruthachadh. Le bhith a’ cur chlasaichean atharrachaidh gutter ris , bidh cutairean againn ann an treòrachadh còmhnard is dìreach. Air puirt-seallaidh gluasadach cumhang, bidh an .col-12cuideachadh a’ cruachadh smachdan an fhoirm agus barrachd. Bidh .align-items-centerna h-eileamaidean cruth a 'co-thaobhadh ris a' mheadhan, a 'dèanamh co- .form-checkboxthaobhadh ceart.

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