Skip to content

CSS: form-field-group

.instui-form-field-group — 一個帶有標題(legend)、可為欄或內聯佈局,且間距可調的 <fieldset> 群組。

在欄位間設定其自身的 gap,可透過下方的 -col-spacing-*/-row-spacing-* 修飾子調整 — 優先使用它們,而非串接通用的 -gap-* 間距工具修飾子,因為後者會直接覆寫內建值。

Source: form-field-group.css

無障礙

以原生的 <fieldset> 搭配 <legend> 呈現,讓標題文字能為輔助技術命名整個群組。

使用方法

css
@import "@pantoken/components/components.css";
@import "@pantoken/components/form-field-group.css";

範例

html
<fieldset class="instui-form-field-group -layout-columns -col-spacing-medium">
  <legend>Shipping address</legend>
  <label class="instui-form-field">
    <span class="label">First name</span>
    <span class="controls"><input class="instui-text-input"></span>
  </label>
  <label class="instui-form-field">
    <span class="label">Last name</span>
    <span class="controls"><input class="instui-text-input"></span>
  </label>
  <label class="instui-form-field">
    <span class="label">City</span>
    <span class="controls"><input class="instui-text-input"></span>
  </label>
  <label class="instui-form-field">
    <span class="label">State</span>
    <span class="controls">
      <select class="instui-simple-select">
        <option>CA</option>
        <option>NY</option>
        <option>TX</option>
      </select>
    </span>
  </label>
  <div class="instui-form-field-messages">
    <span class="instui-form-field-message -type-hint">All fields are used for delivery only.</span>
  </div>
</fieldset>

結構

text
.instui-form-field-group.-layout-columns.-col-spacing-medium
  legend
  form-field (component)
  form-field-messages (component)
flowchart TD n0[".instui-form-field-group.-layout-columns.-col-spacing-medium"]:::cssdoc-root n1("legend"):::cssdoc-part n2(["form-field"]):::cssdoc-component n3(["form-field-messages"]):::cssdoc-component n0 --> n1 n0 --> n2 n0 --> n3 click n2 "/api/css/form-field.md" click n3 "/api/css/form-field-messages.md" classDef cssdoc-root stroke-width:1px; classDef cssdoc-part stroke-width:1px; classDef cssdoc-slot stroke-width:1px; classDef cssdoc-component stroke-width:1px;

修飾器

修飾器說明
.-col-spacing-large大型欄間距。
.-col-spacing-medium中型欄間距。
.-col-spacing-none無欄間距。
.-col-spacing-small小型欄間距。
.-layout-aligned將子欄位對齊到共用格線。
.-layout-columns以欄的方式排列子欄位。
.-layout-inline將子欄位內聯排列成一列。
.-required將此群組標記為必填。
.-row-spacing-large大型列間距。
.-row-spacing-medium中型列間距。
.-row-spacing-none無列間距。
.-row-spacing-small小型列間距。
.-v-align-bottom欄位靠底部對齊。
.-v-align-middle欄位置中對齊。
.-v-align-top欄位靠頂部對齊。

偽元素

偽元素說明
::after當群組為必填時,於標題文字後呈現裝飾用的必填星號。

條件

型別查詢說明
supports(grid-template-columns: subgrid)

已使用的代幣

Token型別
--instui-component-form-field-layout-asterisk-color<color>LightDarklight-dark(#CF1F24, #FA917F)
--instui-component-form-field-layout-font-family[ <font-family-name> | <generic-font-family> ]#Atkinson Hyperlegible Next, "Helvetica Neue", Helvetica, Arial, sans-serif
--instui-component-form-field-layout-font-size<length>1rem
--instui-component-form-field-layout-font-weight<integer>400
--instui-component-form-field-layout-gap-inputs<length>0.75rem
--instui-component-form-field-layout-gap-primitives<length>0.5rem
--instui-component-form-field-layout-line-height<length>1.125rem
--instui-component-form-field-layout-text-color<color>LightDarklight-dark(#273540, #ffffff)
--instui-spacing-space-lg<length>1rem
--instui-spacing-space-md<length>0.75rem
--instui-spacing-space-sm<length>0.5rem

瀏覽器支援

  • -layout-aligned 模式在 @supports 保護下使用 CSS subgrid;當 subgrid 不被支援時,欄位會退回各自的堆疊佈局。

子元件

相關