Bootstrap表单
Bootstrap 提供了下列类型的表单布局:
- 垂直表单(默认) -> 这个不好看,都是手机版了,PC版占一排不好看;
- 内联表单 -> 我相信这个才是你想要的,PC版响应横排,手机版响应竖排。
- 水平表单 -> 用栅格系统控制显示
一、垂直表单
垂直表单使用的标准步骤
- <form> 元素添加 role="form"。
- 把标签和控件放在一个带有"form-group"的<div> 中,获取最佳间距。
- 向所有的文本元素 <input>、<textarea> 和 <select> 添加"form-control"样式。
<form role="form">
<div class="form-group">
<label for="name">名称</label>
<input type="text" class="form-control" id="name" placeholder="请输入名称">
</div>
<div class="form-group">
<label for="name">年龄</label>
<input type="text" class="form-control" id="name" placeholder="请输入年龄">
</div>
</form>
二、内联布局
内联布局与垂直布局其他完全一样,只是需要给<form role="form">加个class=form-inline。
<form role="form" class="form-inline">
使用这样的内联布局之后,就是大屏幕横排显示,小屏幕垂直显示。
小屏幕:

大屏幕:

内联布局与垂直布局基本一样,只需要给Form加上class="form-inline"。
三、水平表单
水平表单指的是Label标签与控件(input、button)之间的水平。
其使用步骤如下:
- 向父 <form> 元素添加 class .form-horizontal。
- 把标签和控件放在一个带有 class .form-group 的 <div> 中。
- 向标签添加 class .control-label。
<form role="form" class="form-horizontal">
<div class="form-group">
<label for="name" class="control-label col-sm-2">名称</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" placeholder="请输入名称">
</div>
</div>
<div class="form-group">
<label for="name" class="control-label col-sm-2">年龄</label>
<div class="col-sm-10">
<input type="text" class="form-control col-sm-10" id="name" placeholder="请输入年龄">
</div>
</div>
</form>
使用了form-horizontal之后,才能给input控件套div,并且div也能够使用网格系统了。form-horizontal样式改变了.form-group的行为,将其表现得像栅格中的行(row)一样。
四、复选框Checkbox和单选框Radio
这两个控件在Bootstrap里面比较特殊,有时候需要横排,有时候需要竖排。
它也跟form一样,也是有内联的。
- 如果需要内联显示,则设置其外层包围的label的class为checkbox-inline。
- 如果需要默认的竖排显示,则设置外层包围的label的class为heckbox。
<form role="form">
<!-- 复选 -->
<div class="checkbox">
<label><input type="checkbox" value="">香蕉</label>
</div>
<div class="checkbox">
<label><input type="checkbox" value="">苹果</label>
</div>
<div class="checkbox">
<label><input type="checkbox" value="">西瓜</label>
</div> <div class="checkbox-inline">
<label><input type="checkbox" value="">香蕉</label>
</div>
<div class="checkbox-inline">
<label><input type="checkbox" value="">苹果</label>
</div>
<div class="checkbox-inline">
<label><input type="checkbox" value="">西瓜</label>
</div> <!-- 单选 -->
<div class="radio">
<label>
<input type="radio" name="optionsRadios" value="option1" checked> 男
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" value="option2" checked> 女
</label>
</div> <div class="checkbox-inline">
<label>
<input type="radio" name="optionsRadios" value="option1" checked> 男
</label>
</div>
<div class="checkbox-inline">
<label>
<input type="radio" name="optionsRadios" value="option2" checked> 女
</label>
</div>
</form>
其显示效果如下:

五、静态控件
静态控件指的是那些不能够改变值的控件,在bootstrap中,当您需要在一个水平表单内的表单标签后放置纯文本时,请在 <p> 上使用class="form-control-static"。
<form role="form">
<div class="form-group">
<label class="col-sm-1 control-label">名称</label>
<div class="col-sm-11">
<p class="form-control-static">刘玄德</p>
</div>
</div>
</form>
显示效果如下:

六、表单帮助文本
Bootstrap表单帮助文本一般指的是输入录入的提示,通常在input后面跟个.help-block的HTML元素就可以了。
<form role="form">
<div class="form-group">
<input class="form-control" type="text" >
<span class="help-block">
特别提醒,如果你没有什么,就不要输入了。
</span>
</div>
</form>
显示效果如下:

除了这些之外,Bootstrap还有很多用来控制input高度啊,输入是否成功啊等等的一些列样式,这些只要查一下,找到相应的关键字就能够用,以后遇到奇葩的再记录。
Bootstrap表单的更多相关文章
- bootstrapValidator.js,最好用的bootstrap表单验证插件
前言:做Web开发的我们,表单验证是再常见不过的需求了.友好的错误提示能增加用户体验.博主搜索bootstrap表单验证,搜到的结果大部分都是文中的主题:bootstrapvalidator.今天就来 ...
- bootstrap表单带验证
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...
- 详解Bootstrap表单组件
表单常见的元素主要包括:文本输入框.下拉选择框.单选框.复选框.文本域.按钮等.下面是不同的bootstrap版本: LESS: forms.less SASS: _forms.scss boot ...
- bootstrap 表单控件 控件状态 控件大小 help-block
bootstrap 表单控件 控件状态 控件大小 help-block <!DOCTYPE html> <html lang="en"> <head& ...
- 基于Bootstrap表单验证
基于Bootstrap表单验证 GitHub地址:https://github.com/chentangchun/FormValidate 使用方式: 1.CSS样式 .valierror { bor ...
- 第二百三十四节,Bootstrap表单和图片
Bootstrap表单和图片 学习要点: 1.表单 2.图片 本节课我们主要学习一下 Bootstrap 表单和图片功能,通过内置的 CSS 定义,显示各 种丰富的效果. 一.表单 Bootstrap ...
- 测开之路一百一十一:bootstrap表单
bootstrap表单 引入bootstrap和jquery 默认表单 垂直表单 表单属性绑定:for属性,当for的属性和id的属性相同时,单击for标签,光标自动跳到相同属性的输入框 复选框 水平 ...
- bootstrap 表单类
bootstrap 表单类 表单美化 用法: 向父元素 <form role="form"></form> 添加 role="form&q ...
- Bootstrap表单验证插件bootstrapValidator使用方法整理
插件介绍 先上一个图: 下载地址:https://github.com/nghuuphuoc/bootstrapvalidator 使用方法:http://www.cnblogs.com/huangc ...
随机推荐
- Invert Binary Tree
Invert a binary tree: 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 简单递归实现,调换左右子树,子树的所有子树结构 ...
- JavaScript 表单验证
长度限制: <script>function test(){if(document.a.b.value.length>50){alert("不能超过50个字符!" ...
- 不能从const char *转换为LPCWSTR
编译器有时候会根据编码方式来选择定义为LPCWSTR还是LPCTSTR LPSTR: 32bit指针 指向一个字符串,每个字符占1字节. 相当于 char * LPCSTR: 32-bit指针 指 ...
- 自建yum源及分组安装
最近在研究一套自动化运维方向的框架,在想到远程安装软件包的时候,觉得有yum支持会更方便一些.主要思路是把程序员写的代码或程序打包成rpm,然后提交到自建yum源,并实现按组安装,本地yum源实现步骤 ...
- OpenGL观察轴
旋转矩阵可以通过观察向量构造,观察向量可以是3D空间的两个或三个点.如果一个处于P1点的对象面向P2点,则观察向量就是P2-P1,如下图: 首先,前轴向量通过归一化的观察向量简单计算而来. 其次,左轴 ...
- MSI Error 1603 installing AppFabric 1.1 / Win7 x64
MSI Error 1603 installing AppFabric 1.1 / Win7 x64 Archived Forums A-B > AppFabric Caching 先说解 ...
- (转)php-curl响应慢(开发微信授权登陆时碰到的问题)
最近在做一个php小项目的时候,发现curl调用微信的授权api.weixin.qq.com,经常是需要等待很久,但是有时候却很快. 刚开始以为是网络慢问题,没去注意.后面通过打上时间日志观察发现,慢 ...
- [2014.01.27]wfRadar 雷达图组件 2.5
全新开发的雷达图组件--wfRadar,使用简单,功能强大,图像处理效果极佳. 组件支持多种图片格式,包括bmp,jpg,gif,wmf,emf,ico,png,pcx,tif,tga,pcx,dcx ...
- Asp.net中文件的压缩与解压
这里笔者为大家介绍在asp.net中使用文件的压缩与解压.在asp.net中使用压缩给大家带来的好处是显而易见的,首先是减小了服务器端文件存储的空间,其次下载时候下载的是压缩文件想必也会有效果吧,特别 ...
- Lab_7_Automating_v2.5
System Operations - Lab 7: Automating Deployments with CloudFormation - 2.5 ======================== ...