Bootstrap简单表单显示学习笔记
表单布局
垂直或基本表单
基本的表单结构时BootStrap自带的,创建基本表单的步骤如下:
1、向父<form>元素添加role = “form”;
2、为了获取最佳的间距,把标签和控件放在一个div.form-group中,div放在父form下;
3、向所有的文本元素<input>、<textarea>和<select>添加.form-control
<!DOCTYPE html> <html> <head> <title>Bootstrap 模板</title> <meta charset="utf-8"> <!-- 引入 Bootstrap --> <link href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <form role="form"> <div class="form-group"> <label for="name">名称</label> <input type="text" class="form-control" id="name" name="name-text" placeholder="请输入你的名称"> </div> </form> <!-- jQuery (Bootstrap 的 JavaScript 插件需要引入 jQuery) --> <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script> <!-- 包括所有已编译的插件 --> <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script> </body> </html>
添加了form-controlClass的input会和label分为两行,并且获得焦点时会有蓝色的边框样式。
内联表单
内联表单中所有的元素都是内联的,标签都是并排的
1、向<form>标签中添加classfrom-inline;
2、每个表单需要被包含在div.form-group,checkbox可以包含在div.checkbox,radio可以包含在div.radio;
3、默认情况下,bootstrap中的input、select和textarea有100%宽度,使用内联表单时,可以设置表单控件的宽度来设置;
4、对标签描述添加sr-only可以隐藏标签描述。
<!DOCTYPE html> <html> <head> <title>Bootstrap 模板</title> <meta charset="utf-8"> <!-- 引入 Bootstrap --> <link href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <form class="form-inline" role="form"> <div class="form-group"> <label class = "sr-only" for="name">名称</label> <input type="text" class="form-control" id="name" name="name-text" placeholder="请输入你的名称" style="width: 170px"> </div> <div class="form-group"> <input type="file" name="inputfile" style="width: 170px"> </div> <label> <input type="checkbox" class="checkbox">请打勾 </label> </form> <!-- jQuery (Bootstrap 的 JavaScript 插件需要引入 jQuery) --> <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script> <!-- 包括所有已编译的插件 --> <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script> </body> </html>
如果大家还想深入学习,可以点击这里进行学习,再为大家附3个精彩的专题:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
IE8 下的Js错误HTML Parsing Error...
今天调试一段JS代码出现这个状况..在火狐 IE7 和IE6下都正常...郁闷,在网上搜索了一下相关资料 一般错误都是指所指定的标签没有加载完就是用该对象....2009-08-08JavaScript使用forEach()与jQuery使用each遍历数组时return false 的区别
这篇文章主要介绍了JavaScript使用forEach()与jQuery使用each遍历数组时return false 的区别,非常不错,需要的朋友可以参考下2016-08-08jQuery NProgress.js加载进度插件的简单使用方法
NProgress是基于jquery的,且版本要 >1.8 。这篇文章主要介绍了NProgress.js加载进度插件的简单使用方法,需要的朋友可以参考下2018-01-01
最新评论