Bootstrap简单表单显示学习笔记

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Bootstrap简单表单显示学习笔记

帆帆帆   2020-05-15 我要评论

表单布局

垂直或基本表单

基本的表单结构时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个精彩的专题:

Bootstrap学习教程

Bootstrap实战教程

Bootstrap插件使用教程

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们