表单字段
用途
Add your field HTML
Use class="field" for one control and class="fieldset" for related controls. Use a native <fieldset> when the group needs a <legend>; otherwise use a labelled role="group".
HTML 结构
<fieldset class="fieldset">- Native group for related fields. Use
<legend>for the label and a following<p>for description. <div role="group" class="fieldset">- Structural group when
<fieldset>is not appropriate. Addaria-labeloraria-labelledby. <div role="group" class="field">- Single field wrapper. Add
data-orientationwhen needed. <label>- Label for the control. Use
forwhen the control has anid. <input>,<select>,<textarea>- Native form control. Put
aria-invalid="true"on the invalid control, not only on the wrapper. <section>- Optional content wrapper for label and description when the control sits beside text.
<p>- Helper text or error text. Use
role="alert"for validation errors and connect it witharia-describedby.
示例
输入
文本区域
选择
Select your department or area of work.
滑块
Set your maximum budget (up to $800).
现场组
复选框
Your Desktop & Documents folders are being synced with iCloud Drive. You can access them from other devices.
收音机
开关
Enable multi-factor authentication. If you do not have a two-factor device, you can use a one-time code sent to your email.
选择卡
Wrap a .field inside a <label> to create selectable field cards. This works with radio, checkbox, and switch controls.
现场组
将字段堆叠在组内并使用 .field-separator 来划分部分。
响应式布局
默认情况下使用 data-orientation="responsive" 堆叠,并在较宽的容器中切换为水平堆叠。
验证和错误
将 data-invalid 添加到 .field,将 aria-invalid="true" 添加到无效控制。
Enter a valid email address.
RTL
将 dir="rtl" 添加到字段、字段集或祖先。