Bootstrap CSS 表单参考


Bootstrap的默认设置

各个表单控件会通过 Bootstrap 自动接收一些全局样式。

所有带有 class="form-control" 的文本 <input>、<textarea> 和 <select> 元素都设置为 width: 100%;默认情况下。

所有三种表单布局的标准规则:

  • 将标签和表单控件包装在<div class="form-group">(最佳间距所需)
  • 添加类.form-control对所有文本<input>,<textarea>, 和<select>元素

以下示例创建一个简单的 Bootstrap 表单,其中包含两个输入字段、一个复选框和一个提交按钮:

Bootstrap 表单示例

<form>
  <div class="form-group">
    <label for="email">Email address:</label>
    <input type="email" class="form-control" id="email">
  </div>
  <div class="form-group">
    <label for="pwd">Password:</label>
    <input type="password" class="form-control" id="pwd">
  </div>
  <div class="checkbox">
    <label><input type="checkbox"> Remember me</label>
  </div>
  <button type="submit" class="btn btn-default">Submit</button>
</form>
亲自试一试 »

表格类

Class Description Example
.form-inline Makes a <form> left-aligned with inline-block controls (This only applies to forms within viewports that are at least 768px wide) 尝试一下
.form-horizontal Aligns labels and groups of form controls in a horizontal layout 尝试一下
.form-control Used on input, textarea, and select elements to span the entire width of the page and make them responsive 尝试一下
.form-control-feedback Form validation class 尝试一下
.form-control-static Adds plain text next to a form label within a horizontal form 尝试一下
.form-group Container for form input and label 尝试一下

输入类

Class Description Example
.input-group Container to enhance an input by adding an icon, text or a button in front or behind it as a "help text" 尝试一下
.input-group-lg Large input group 尝试一下
.input-group-sm Small input group 尝试一下
.input-group-addon Together with the .input-group class, this class makes it possible to add an icon or help text next to the input field 尝试一下
.input-group-btn Together with the .input-group class, this class attaches a button next to an input. Often used as a search bar 尝试一下
.input-lg Large input field 尝试一下
.input-sm Small input field 尝试一下