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。

子组件

相关