htmlman0 2016-12-07
Bootstrap 通过一些简单的 HTML 标签和扩展的类即可创建出不同样式的表单。
0x01 样式1
一个登录界面:
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="../../css/bootstrap.min.css" rel="stylesheet"> <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script> <script src="../../js/bootstrap.min.js"></script> <title>用户登录</title> </head> <body> <div class="container"> <form> <div class="form-group"> <label for="UserName">用户名</label> <input type="text" class="form-control" id="UserName" placeholder="用户名"> </div> <div class="form-group"> <label for="PassWord">密 码</label> <input type="password" class="form-control" id="PassWord" placeholder="密码"> </div> <div class="form-group"> <label> <input type="checkbox">记住我吗? </label> </div> <div class="form-group"> <input type="button" class="btn btn-default" id="Submit" value="登 录"> </div> </form> </div> </body> </html>
效果如下:
0x02 样式2
如果要将label与文本框在同一行显示,修改如下:
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="../../css/bootstrap.min.css" rel="stylesheet"> <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script> <script src="../../js/bootstrap.min.js"></script> <title>用户登录</title> </head> <body> <div class="container"> <div class="col-lg-3 col-md-3 col-xs-3"></div> <div class="col-lg-6 col-md-6 col-xs-6"> <div class="page-header"> <h1>用户登录</h1> </div> <form class="form-horizontal"> <div class="form-group"> <div class="col-lg-2 col-sm-2 col-xs-2"> <label for="UserName" class="control-label">用户名:</label> </div> <div class="col-lg-10 col-sm-10 col-xs-10"> <input type="text" class="form-control" id="UserName" placeholder="用户名"> </div> </div> <div class="form-group"> <div class="col-lg-2 col-sm-2 col-xs-2"> <label for="PassWord" class="control-label">密 码:</label> </div> <div class="col-lg-10 col-sm-10 col-xs-10"> <input type="password" class="form-control" id="PassWord" placeholder="密码"> </div> </div> <div class="form-group"> <div class="col-lg-2 col-sm-2 col-xs-2"></div> <div class="col-lg-10 col-sm-10 col-xs-10"> <div class="checkbox"> <label> <input type="checkbox">记住我吗? </label> </div> </div> </div> <div class="form-group"> <div class="col-lg-2 col-sm-2 col-xs-2"></div> <div class="col-lg-10 col-sm-10 col-xs-10"> <input type="button" class="btn btn-default" id="Submit" value="登 录"> </div> </div> </form> </div> <div class="col-lg-3 col-md-3 col-xs-3"></div> </div> </body> </html>
效果如下:
0x03 样式3
如果将文本框放在同一行,修改如下:
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="../../css/bootstrap.min.css" rel="stylesheet"> <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script> <script src="../../js/bootstrap.min.js"></script> <title>用户登录</title> </head> <body> <div class="container"> <form class="form-inline"> <div class="form-group"> <label class="control-label" for="UserName">用户名:</label> <input type="text" class="form-control" id="UserName" placeholder="用户名"> </div> <div class="form-group"> <label class="control-label" for="PassWord">密 码:</label> <input type="password" class="form-control" id="PassWord" placeholder="密码"> </div> <div class="form-group"> <div class="checkbox"> <label> <input type="checkbox">记住我吗? </label> </div> </div> <div class="form-group"> <input type="button" class="btn btn-default" id="Submit" value="登 录"> </div> </form> </div> </body> </html>
效果如下:
向父 <form> 元素添加 role="form"。把标签和控件放在一个带有 class .form-group 的 <div> 中。这是获取最佳间距所必需的。向所有的文本元素 <input>、&l
表单中常见的元素主要包括:文本输入框、下拉选择框、单选按钮、复选按钮、文本域和按钮等。<input type="email" class="form-control" id="exampleInput
本文主要给大家介绍了bootstrap表单样式的使用知识,非常不错,一起看看吧!<input type="email" class="form-control" id="exampleInputEma