Bootstrap学习
Bootstrap学习之 - 表格
表格(<table>)
table-striped :每一行增加斑马条纹样式。
thead : 指定表格最上行
tfoot :指定表格最下行
table-bordered :为表格和其中的每个单元格增加边框。
table-hover :每一行对鼠标悬停状态作出响应。
table-condensed : 让表格更加紧凑,单元格中的内补(padding)均会减半。
.active :鼠标悬停在行或单元格上时所设置的颜色
.success :标识成功或积极的动作
.info :标识普通的提示信息或动作
.warning :标识警告或需要用户注意
.danger :标识危险或潜在的带来负面影响的动作table-responsive :可创建响应式表格,其会在小屏幕设备上(小于768px)水平滚动。当屏幕大于 768px 宽度时,水平滚动条消失。
样例代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap3/css/bootstrap.min.css"> <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap3/css/bootstrap-theme.min.css"> <script src="${pageContext.request.contextPath}/bootstrap3/js/jquery-1.7.2.min.js"></script> <script src="${pageContext.request.contextPath}/bootstrap3/js/bootstrap.min.js"></script> </head> <body > <div style="padding: 20px;"> <form class="form-horizontal"> <p>输入框 </p> <div class="form-group"> <div> <input type="text" class="form-control" placeholder="please input something……"/> </div> </div> <hr/> <p>文本域 </p> <div class="form-group"> <div> <textarea class="form-control" rows="3" placeholder="please input something……"></textarea> </div> </div> <hr/> <p>多选和单选框 </p> <div class="checkbox"> <label> <input type="checkbox" value=""/> Option one is this and that—be sure to include why it's great </label> </div> <div class="checkbox disabled"> <label> <input type="checkbox" value="" disabled/> Option two is disabled </label> </div> <div class="radio"> <label> <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked/> Option one is this and that—be sure to include why it's great </label> </div> <div class="radio"> <label> <input type="radio" name="optionsRadios" id="optionsRadios2" value="option2"/> Option two can be something else and selecting it will deselect option one </label> </div> <div class="radio disabled"> <label> <input type="radio" name="optionsRadios" id="optionsRadios3" value="option3" disabled/> Option three is disabled </label> </div> <hr/> <p>内联单选框 </p> <div> <label class="checkbox-inline"> <input type="checkbox" id="inlineCheckbox1" value="option1" checked/> 1 </label> <label class="checkbox-inline"> <input type="checkbox" id="inlineCheckbox2" value="option2"/> 2 </label> <label class="checkbox-inline"> <input type="checkbox" id="inlineCheckbox1" value="option1"/> 3 </label> <label class="checkbox-inline"> <input type="checkbox" id="inlineCheckbox2" value="option2" disabled/> 4 </label> </div> <hr/> <p>内联多选框 </p> <div> <label class="radio-inline"> <input type="radio" name="radio_inline" id="inlineradio1" value="option1" checked/> 1 </label> <label class="radio-inline"> <input type="radio" name="radio_inline" id="inlineradio2" value="option2"/> 2 </label> <label class="radio-inline"> <input type="radio" name="radio_inline" id="inlineradio3" value="option3" disabled/> 3 </label> </div> <hr/> <p>下拉列表</p> <div style="width:200px;"> <select class="form-control"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option selected>5</option> <option>6</option> </select> </div> <hr/> <p>支持多选下拉列表 </p> <div style="width:200px;"> <select multiple class="form-control"> <option selected>1</option> <option selected>2</option> <option selected>3</option> <option>4</option> <option>5</option> <option>6</option> </select> </div> </form> <hr/> <form class="form-horizontal"> <p>静态控件</p> <div class="form-group"> <label class="control-label col-sm-2">Email</label> <div class="col-sm-10"> <p class="form-control-static">email@example.com</p> </div> </div> <div class="form-group"> <label class="control-label col-sm-2">Password</label> <div class="col-sm-10"> <input type="password" placeholder="Password" class="form-control"/> </div> </div> </form> <form class="form-inline"> <div class="form-group"> <label class="sr-only">Email</label> <p class="form-control-static">email@example.com</p> </div> <div class="form-group"> <label for="inputPassword2" class="sr-only">Password</label> <input type="password" class="form-control" id="inputPassword2" placeholder="Password"> </div> <button type="submit" class="btn btn-default">Sign in</button> </form> <form> <div class="form-group has-success has-feedback"> <label class="control-label" for="inputSuccess2">Input with success</label> <input type="text" class="form-control" id="inputSuccess2" aria-describedby="inputSuccess2Status"> <span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span> <span id="inputSuccess2Status" class="sr-only">(success)</span> </div> <div class="form-group has-warning has-feedback"> <label class="control-label" for="inputWarning2">Input with warning</label> <div class="input-group"> <span class="input-group-addon">Warning</span> <input type="text" class="form-control" id="inputWarning2" aria-describedby="inputWarning2Status"> <span class="glyphicon glyphicon-warning-sign form-control-feedback" aria-hidden="true"></span> <span id="inputWarning2Status" class="sr-only">(warning)</span> </div> </div> <div class="form-group has-error has-feedback"> <label class="control-label" for="inputError2">Input with error</label> <div class="input-group"> <span class="input-group-addon">Error </span> <input type="text" class="form-control" id="inputError2" aria-describedby="inputError2Status"> <span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span> <span id="inputError2Status" class="sr-only">(error)</span> </div> </div> <div class="form-group has-success has-feedback"> <label class="control-label" for="inputGroupSuccess1">Input group with success</label> <div class="input-group"> <span class="input-group-addon">Sucess </span> <input type="text" class="form-control" id="inputGroupSuccess1" aria-describedby="inputGroupSuccess1Status"> </div> <span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span> <span id="inputGroupSuccess1Status" class="sr-only">(success)</span> <span class="aria-describedby">我是辅助文本,辅助你去了解上一行需要填写什么内容</span> </div> </form> </div> </body> </html>
效果图:
Bootstrap学习之 - 表单
form-group :使用组将控件管理起来,并样式化
form-control :对于表单中的控件进行了样式化
form-inline :内联表单(显示在一行)
placeholder : 提示信息
help-block :帮助提示信息
普通表单
样例代码:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap3/css/bootstrap.min.css"> <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap3/css/bootstrap-theme.min.css"> <script src="${pageContext.request.contextPath}/bootstrap3/js/jquery-1.7.2.min.js"></script> <script src="${pageContext.request.contextPath}/bootstrap3/js/bootstrap.min.js"></script> </head> <body > <div style="padding: 20px;"> <form > <div class="form-group"> <label>Email address</label> <input type="email" class="form-control" placeholder="Enter Email"> </div> <div class="form-group"> <label>Password</label> <input type="password" class="form-control" placeholder="Password"> </div> <div class="form-group"> <label>File input</label> <input type="file" class="form-control"> <p class="help-block">Example block-level help text here.</p> </div> <div class="checkbox"> <label> <input type="checkbox">check me out </label> </div> <button type="submit">btn btn-default</button> </form> </div> </body> </html>
效果图:
内联表单
form-inline :表单内的所有控件单行内显示
样例代码:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap3/css/bootstrap.min.css"> <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap3/css/bootstrap-theme.min.css"> <script src="${pageContext.request.contextPath}/bootstrap3/js/jquery-1.7.2.min.js"></script> <script src="${pageContext.request.contextPath}/bootstrap3/js/bootstrap.min.js"></script> </head> <body > <div style="padding: 20px;"> <form class="form-inline"> <div class="form-group"> <input type="email" class="form-control" placeholder="Enter Email"> </div> <div class="form-group"> <input type="password" class="form-control" placeholder="Password"> </div> <div class="checkbox"> <label> <input type="checkbox"> Remember me </label> </div> <button type="submit">Sign in</button> </form> </div> </body> </html>
效果图
水平排列的表单
form-horizontal :水平以网格形式进行控件对齐
样例代码:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap3/css/bootstrap.min.css"> <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap3/css/bootstrap-theme.min.css"> <script src="${pageContext.request.contextPath}/bootstrap3/js/jquery-1.7.2.min.js"></script> <script src="${pageContext.request.contextPath}/bootstrap3/js/bootstrap.min.js"></script> </head> <body > <div style="padding: 20px;"> <form class="form-horizontal"> <div class="form-group"> <label class="col-sm-2 control-label">Email</label> <div class="col-sm-8"> <input type="email" class="form-control" placeholder="Enter Email"> </div> </div> <div class="form-group"> <label class="col-sm-2 control-label">Password</label> <div class="col-sm-8"> <input type="password" class="form-control" placeholder="Password"> </div> </div> <div class="form-group"> <div class="checkbox col-sm-offset-2 col-sm-8"> <label> <input type="checkbox"> Remember me </label> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-8"> <button type="submit">Sign in</button> </div> </div> </form> </div> </body> </html>
效果图:
被支持的表单中的控件
texttextareacheckboxradio :<input type="radio" name="optionsRadios" checked name 标示为一组 ;checked标示为选中;disabled 标示为不可选中;
password
datetime
datetime-local
date
month
time
week
number
url
search
tel
color
— : -
sr-only :隐藏表单中当前的控件的
input-lg :控制控件尺寸(lg sm)
form-group-sm :表单组的尺寸col-xs-2 :列的尺寸
aria-describedby :辅助文本
样例代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap3/css/bootstrap.min.css"> <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap3/css/bootstrap-theme.min.css"> <script src="${pageContext.request.contextPath}/bootstrap3/js/jquery-1.7.2.min.js"></script> <script src="${pageContext.request.contextPath}/bootstrap3/js/bootstrap.min.js"></script> </head> <body > <div style="padding: 20px;"> <form class="form-horizontal"> <p>输入框 </p> <div class="form-group"> <div> <input type="text" class="form-control" placeholder="please input something……"/> </div> </div> <hr/> <p>文本域 </p> <div class="form-group"> <div> <textarea class="form-control" rows="3" placeholder="please input something……"></textarea> </div> </div> <hr/> <p>多选和单选框 </p> <div class="checkbox"> <label> <input type="checkbox" value=""/> Option one is this and that—be sure to include why it's great </label> </div> <div class="checkbox disabled"> <label> <input type="checkbox" value="" disabled/> Option two is disabled </label> </div> <div class="radio"> <label> <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked/> Option one is this and that—be sure to include why it's great </label> </div> <div class="radio"> <label> <input type="radio" name="optionsRadios" id="optionsRadios2" value="option2"/> Option two can be something else and selecting it will deselect option one </label> </div> <div class="radio disabled"> <label> <input type="radio" name="optionsRadios" id="optionsRadios3" value="option3" disabled/> Option three is disabled </label> </div> <hr/> <p>内联单选框 </p> <div> <label class="checkbox-inline"> <input type="checkbox" id="inlineCheckbox1" value="option1" checked/> 1 </label> <label class="checkbox-inline"> <input type="checkbox" id="inlineCheckbox2" value="option2"/> 2 </label> <label class="checkbox-inline"> <input type="checkbox" id="inlineCheckbox1" value="option1"/> 3 </label> <label class="checkbox-inline"> <input type="checkbox" id="inlineCheckbox2" value="option2" disabled/> 4 </label> </div> <hr/> <p>内联多选框 </p> <div> <label class="radio-inline"> <input type="radio" name="radio_inline" id="inlineradio1" value="option1" checked/> 1 </label> <label class="radio-inline"> <input type="radio" name="radio_inline" id="inlineradio2" value="option2"/> 2 </label> <label class="radio-inline"> <input type="radio" name="radio_inline" id="inlineradio3" value="option3" disabled/> 3 </label> </div> <hr/> <p>下拉列表</p> <div style="width:200px;"> <select class="form-control"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option selected>5</option> <option>6</option> </select> </div> <hr/> <p>支持多选下拉列表 </p> <div style="width:200px;"> <select multiple class="form-control"> <option selected>1</option> <option selected>2</option> <option selected>3</option> <option>4</option> <option>5</option> <option>6</option> </select> </div> </form> <hr/> <form class="form-horizontal"> <p>静态控件</p> <div class="form-group"> <label class="control-label col-sm-2">Email</label> <div class="col-sm-10"> <p class="form-control-static">email@example.com</p> </div> </div> <div class="form-group"> <label class="control-label col-sm-2">Password</label> <div class="col-sm-10"> <input type="password" placeholder="Password" class="form-control"/> </div> </div> </form> <form class="form-inline"> <div class="form-group"> <label class="sr-only">Email</label> <p class="form-control-static">email@example.com</p> </div> <div class="form-group"> <label for="inputPassword2" class="sr-only">Password</label> <input type="password" class="form-control" id="inputPassword2" placeholder="Password"> </div> <button type="submit" class="btn btn-default">Sign in</button> </form> <form> <div class="form-group has-success has-feedback"> <label class="control-label" for="inputSuccess2">Input with success</label> <input type="text" class="form-control" id="inputSuccess2" aria-describedby="inputSuccess2Status"> <span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span> <span id="inputSuccess2Status" class="sr-only">(success)</span> </div> <div class="form-group has-warning has-feedback"> <label class="control-label" for="inputWarning2">Input with warning</label> <div class="input-group"> <span class="input-group-addon">Warning</span> <input type="text" class="form-control" id="inputWarning2" aria-describedby="inputWarning2Status"> <span class="glyphicon glyphicon-warning-sign form-control-feedback" aria-hidden="true"></span> <span id="inputWarning2Status" class="sr-only">(warning)</span> </div> </div> <div class="form-group has-error has-feedback"> <label class="control-label" for="inputError2">Input with error</label> <div class="input-group"> <span class="input-group-addon">Error </span> <input type="text" class="form-control" id="inputError2" aria-describedby="inputError2Status"> <span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span> <span id="inputError2Status" class="sr-only">(error)</span> </div> </div> <div class="form-group has-success has-feedback"> <label class="control-label" for="inputGroupSuccess1">Input group with success</label> <div class="input-group"> <span class="input-group-addon">Sucess </span> <input type="text" class="form-control" id="inputGroupSuccess1" aria-describedby="inputGroupSuccess1Status"> </div> <span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span> <span id="inputGroupSuccess1Status" class="sr-only">(success)</span> <span class="aria-describedby">我是辅助文本,辅助你去了解上一行需要填写什么内容</span> </div> </form> </div> </body> </html>
本文详细介绍了Bootstrap中的表格用法,包括table-striped、thead、tfoot等样式,以及表单的各种类型如普通表单、内联表单、水平排列的表单,并展示了各类型表单的样例代码和效果,还提到了Bootstrap支持的表单控件。
840

被折叠的 条评论
为什么被折叠?



