Skip to content

CSS: form-field

.instui-form-field — 表單欄位的包裝:標籤、其控制項,以及內聯、必填或唯讀的配置。

錯誤訊息會隱藏,直到欄位的控制項為 :user-invalid(使用者互動後)或你加入 -invalid 類別。使用 -layout-inline 可將標籤置於控制項旁,使用 -layout-stacked 可將標籤置於上方。此元件也會在標籤、控制項與訊息之間設定自己的 gap;串接 -gap-* 間距工具修飾器會覆寫該內建值。

Source: form-field.css

無障礙

<label> 元素包裹控制項,因此標籤文字會原生為其命名;必填星號僅為裝飾,應對輔助技術隱藏(aria-hidden),而錯誤訊息會在控制項為 :user-invalid 或你加入 -invalid 類別時顯示。

使用方法

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

範例

html
<label class="instui-form-field">
  <span class="label">Email address</span>
  <span class="controls"><input class="instui-text-input" type="email" placeholder="[email protected]"></span>
  <div class="instui-form-field-messages">
    <span class="instui-form-field-message -type-hint">We'll never share it.</span>
    <span class="instui-form-field-message -type-error">Enter a valid email address.</span>
  </div>
</label>

結構

text
.instui-form-field
  .label
  .controls
    text-input (component)
  form-field-messages (component)
flowchart TD n0[".instui-form-field"]:::cssdoc-root n1(".label"):::cssdoc-part n2(".controls"):::cssdoc-part n3(["text-input"]):::cssdoc-component n4(["form-field-messages"]):::cssdoc-component n0 --> n1 n2 --> n3 n0 --> n2 n0 --> n4 click n3 "/api/css/text-input.md" click n4 "/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;

修飾器

修飾器說明
.-inline內聯配置(為 -layout-inline 的簡寫)。
.-invalid無效(錯誤)狀態。
.-label-align-end讓標籤文字靠結尾對齊。
.-label-align-start讓標籤文字靠起始對齊。
.-layout-inline內聯配置:標籤置於控制項旁。
.-layout-stacked堆疊配置:標籤置於控制項上方。
.-readonly唯讀狀態。
.-v-align-bottom讓標籤與控制項底部對齊。
.-v-align-top讓標籤與控制項頂部對齊。

部件

部件說明
.controls標籤旁或下方的控制項區域。
.label欄位標籤。

偽元素

偽元素說明
::after在欄位為必填時,於標籤文字後呈現裝飾用的必填星號。

狀態

狀態說明
:required

已使用的代幣

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-readonly-text-color<color>LightDarklight-dark(#576773, #AAB0B5)
--instui-component-form-field-layout-text-color<color>LightDarklight-dark(#273540, #ffffff)

瀏覽器支援

  • 使用 CSS 的 @scope at-rule 來包含其元素樣式;需較新的 Chromium、Firefox 或 Safari。

子元件

相關