## 1 表单 ### 1)基本表单 Bootstrap 为单独的表单元素预定义了全局样式,表单内元素的具体使用如下: * 设置了 .form-control 类的 ``、`` 和 `` 元素都将被默认设置宽度属性为 width: 100%;。 * 将 label 元素和前面提到的控件包裹在 .form-group 中可以获得最好的排列。 ```html Email address Password Submit ``` ### 2)内联表单 为 `` 元素添加 .form-inline 类可使其内容左对齐并且表现为 inline-block 级别的控件。 > 只适用于 viewport 至少在 768px 宽度时(视口宽度再小的话就会使表单折叠)。 ```html Name Email Send invitation ``` > **需要注意的是:** > > 在内联表单,我们将这些元素的宽度设置为 width: auto;,因此,多个控件可以排列在同一行。 > > 如果你没有为每个输入控件设置 label 标签,屏幕阅读器将无法正确识别。对于这些内联表单,你可以通过为 label 设置 .sr-only 类将其隐藏。 ```html Email address Password Sign in ``` ### 3)水平排列的表单 通过为表单添加 .form-horizontal 类,并联合使用 Bootstrap 预置的栅格类,可以将 label 标签和控件组水平并排布局。 > 这样做将改变 .form-group 的行为,使其表现为栅格系统中的行(row),因此就无需再额外添加 .row 了。 ```html Email Password Sign in ``` ### 4)单选框和多选框 #### a. 默认外观 * 单选框使用 class 为 .radio * 多选框使用 class 为 .checkbox 单选框或多选框的样式要定义在 div 元素中(该元素作为容器元素,包含文本和单选或多选框元素)。 ```html Option one is this and that—be sure to include why it's great Option two is disabled Option one is this and that—be sure to include why it's great Option two can be something else and selecting it will deselect option one Option three is disabled ``` #### b. 内联单选和多选框 通过将 .checkbox-inline 或 .radio-inline 类应用到一系列的多选框(checkbox)或单选框(radio)控件上,可以使这些控件排列在一行。 ```html 1 2 3 1 2 3 ```