表单样式ios
1、基础表单框架
<form > <div class="form-group"> <label>邮箱:</label> <input type="email" class="form-control" placeholder="请输入您的邮箱地址"> </div> <div class="form-group"> <label >密码</label> <input type="password" class="form-control" placeholder="请输入您的邮箱密码"> </div> <div class="checkbox"> <label> <input type="checkbox"> 记住密码 </label> </div> <button type="submit" class="btn btn-default">进入邮箱</button> </form>
表单除了这几个元素以外,还有input、select、textarea等元素,在Bootstrap框架中,经过定制了一个类名`form-control`,也就是说,若是这几个元素使用了类名“form-control”,将会实现一些设计上的定制效果。post
一、宽度变成了100%编码
二、设置了一个浅灰色(#ccc)的边框spa
三、具备4px的圆角设计
四、设置阴影效果,而且元素获得焦点之时,阴影和边框效果会有所变化code
五、设置了placeholder的颜色为#999orm
2、水平表单blog
Bootstrap框架默认的表单是垂直显示风格,但不少时候咱们须要的水平表单风格(标签居左,表单控件居右)。游戏
<form class="form-horizontal" role="form"> <div class="form-group"> <label for="inputEmail3" class="col-sm-2 control-label">邮箱:</label> <div class="col-sm-4"> <input type="email" class="form-control" id="inputEmail3" placeholder="请输入您的邮箱地址"> </div> </div> <div class="form-group"> <label for="inputPassword3" class="col-sm-2 control-label">密码:</label> <div class="col-sm-4"> <input type="password" class="form-control" id="inputPassword3" placeholder="请输入您的邮箱密码"> </div> </div> </form>
在Bootstrap框架中要实现水平表单效果,必须知足如下两个条件:
一、在<form>元素是使用类名“.form-horizontal”。
二、配合Bootstrap框架的网格系统。
在<form>元素上使用类名“.form-horizontal”主要有如下几个做用:
一、设置表单控件padding和margin值。
二、改变“form-group”的表现形式,相似于网格系统的“row”。
3、内联表单
有时候咱们须要将表单的控件都在一行内显示
<form class="form-inline" role="form"> <div class="form-group"> <label class="sr-only" for="exampleInputEmail2">邮箱</label> <input type="email" class="form-control" id="exampleInputEmail2" placeholder="请输入你的邮箱地址"> </div> <div class="form-group"> <label class="sr-only" for="exampleInputPassword2">密码</label> <input type="password" class="form-control" id="exampleInputPassword2" placeholder="请输入你的邮箱密码"> </div> <button type="submit" class="btn btn-default">进入邮箱</button> </form>
在Bootstrap框架中实现这样的表单效果是垂手可得的,你只须要在<form>元素中添加类名“.form-inline”便可。
若是你要在input前面添加一个label标签时,会致使input换行显示。若是你必须添加这样的一个label标签,而且不想让input换行,你须要将label标签也放在容器“form-group”中。
1、输入框input
单行输入框,常见的文本输入框,也就是input的type属性值为text。
在Bootstrap中使用input时也必须添加type类型,若是没有指定type类型,将没法获得正确的样式,由于Bootstrap框架都是经过input[type=“?”]
(其中?号表明type类型,好比说text类型,对应的是input[type=“text”])的形式来定义样式的。
为了让控件在各类表单风格中样式不出错,须要添加类名“.form-control”。
<form role="form"> <div class="form-group"> <input type="email" class="form-control" placeholder="Enter email"> </div> </form>
2、下拉选择框select
Bootstrap框架中的下拉选择框使用和原始的一致,多行选择设置multiple属性的值为multiple。
<form role="form"> <div class="form-group"> <select class="form-control"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> </div> <div class="form-group"> <select multiple class="form-control"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> </div> </form>
3、文本域textarea
文本域和原始使用方法同样,设置rows可定义其高度,设置cols能够设置其宽度。
但若是textarea元素中添加了类名“.form-control”类名,则无需设置cols属性。
由于Bootstrap框架中的“form-control”样式的表单控件宽度为100%或auto。
<form role="form"> <div class="form-group"> <textarea class="form-control" rows="3"></textarea> </div> </form>
4、复选框checkbox和单选择按钮radio
一、不论是checkbox仍是radio都使用label包起来了
二、checkbox连同label标签放置在一个名为“.checkbox”的容器内
三、radio连同label标签放置在一个名为“.radio”的容器内
<form role="form"> <div class="checkbox"> <label> <input type="checkbox" value=""> 记住密码 </label> </div> <div class="radio"> <label> <input type="radio" name="optionsRadios" id="optionsRadios1" value="love" checked> 喜欢 </label> </div> <div class="radio"> <label> <input type="radio" name="optionsRadios" id="optionsRadios2" value="hate"> 不喜欢 </label> </div> </form>
5、复选框和单选按钮水平排列
一、若是checkbox须要水平排列,只须要在label标签上添加类名“.checkbox-inline”
二、若是radio须要水平排列,只须要在label标签上添加类名“.radio-inline”
<form role="form"> <div class="form-group"> <label class="checkbox-inline"> <input type="checkbox" value="option1">游戏 </label> <label class="checkbox-inline"> <input type="checkbox" value="option2">摄影 </label> <label class="checkbox-inline"> <input type="checkbox" value="option3">旅游 </label> </div> <div class="form-group"> <label class="radio-inline"> <input type="radio" value="option1" name="sex">男性 </label> <label class="radio-inline"> <input type="radio" value="option2" name="sex">女性 </label> <label class="radio-inline"> <input type="radio" value="option3" name="sex">中性 </label> </div> </form>
6、表单控件大小
Bootstrap框架还提供了两个不一样的类名,用来控制表单控件的高度。这两个类名是:
一、input-sm:让控件比正常大小更小
二、input-lg:让控件比正常大小更大
这两个类适用于表单中的input,textarea和select控件。
<input class="form-control input-lg" type="text" placeholder="添加.input-lg,控件变大"> <input class="form-control" type="text" placeholder="正常大小"> <input class="form-control input-sm" type="text" placeholder="添加.input-sm,控件变小">
1、焦点状态
焦点状态是经过伪类“:focus”来实现。Bootstrap框架中表单控件的焦点状态删除了outline的默认样式,从新添加阴影效果。
<form role="form" class="form-horizontal"> <div class="form-group"> <div class="col-xs-6"> <input class="form-control input-lg" type="text" placeholder="不是焦点状态下效果"> </div> <div class="col-xs-6"> <input class="form-control input-lg" type="text" placeholder="焦点点状态下效果"> </div> </div> </form>
2、禁用状态
Bootstrap框架的表单控件的禁用状态和普通的表单禁用状态实现方法是同样的,在相应的表单控件上添加属性“disabled”。
<form role="form"> <input class="form-control input-lg" id="disabledInput" type="text" placeholder="表单已被禁用,不可输入" disabled> <fieldset disabled> <div class="form-group"> <label for="disabledTextInput">禁用的输入框</label> <input type="text" id="disabledTextInput" class="form-control" placeholder="禁止输入"> </div> <div class="form-group"> <label for="disabledSelect">禁用的下拉框</label> <select id="disabledSelect" class="form-control"> <option>不可选择</option> </select> </div> <div class="checkbox"> <label> <input type="checkbox"> 没法选择 </label> </div> <button type="submit" class="btn btn-primary">提交</button> </fieldset> </form>
3、验证状态
在制做表单时,难免要作表单验证。一样也须要提供验证状态样式,在Bootstrap框架中一样提供这几种效果。
一、.has-warning:警告状态(黄色)
二、.has-error:错误状态(红色)
三、.has-success:成功状态(绿色)
使用的时候只须要在form-group容器上对应添加状态类名
<form role="form"> <div class="form-group has-success"> <label class="control-label" for="inputSuccess1">成功状态</label> <input type="text" class="form-control" id="inputSuccess1" placeholder="成功状态" > </div> <div class="form-group has-warning"> <label class="control-label" for="inputWarning1">警告状态</label> <input type="text" class="form-control" id="inputWarning1" placeholder="警告状态"> </div> <div class="form-group has-error"> <label class="control-label" for="inputError1">错误状态</label> <input type="text" class="form-control" id="inputError1" placeholder="错误状态"> </div> </form>
日常在制做表单验证时,要提供不一样的提示信息。在Bootstrap框架中也提供了这样的效果。使用了一个"help-block"样式,将提示信息以块状显示,而且显示在控件底部。
<form role="form"> <div class="form-group has-success has-feedback"> <label class="control-label" for="inputSuccess1">成功状态</label> <input type="text" class="form-control" id="inputSuccess1" placeholder="成功状态" > <span class="help-block">你输入的信息是正确的</span> <span class="glyphicon glyphicon-ok form-control-feedback"></span> </div> <div class="form-group has-warning has-feedback"> <label class="control-label" for="inputWarning1">警告状态</label> <input type="text" class="form-control" id="inputWarning1" placeholder="警告状态"> <span class="help-block">请输入正确信息</span> <span class="glyphicon glyphicon-warning-sign form-control-feedback"></span> </div> <div class="form-group has-error has-feedback"> <label class="control-label" for="inputError1">错误状态</label> <input type="text" class="form-control" id="inputError1" placeholder="错误状态"> <span class="glyphicon glyphicon-remove form-control-feedback"></span> </div> </form>
1、多标签支持
通常制做按钮除了使用<button>标签元素以外,还可使用<input type="submit">和<a>标签等。
一样,在Bootstrap框架中制做按钮时,除了刚才所说的这些标签元素以外,还可使用在其余的标签元素上,惟一须要注意的是,要在制做按钮的标签元素上添加类名“.btn”。
<button class="btn btn-default" type="button">button标签按钮</button> <input type="submit" class="btn btn-default" value="input标签按钮"/> <a href="##" class="btn btn-default">a标签按钮</a> <span class="btn btn-default">span标签按钮</span> <div class="btn btn-default">div标签按钮</div>
2、定制风格
在Bootstrap框架中不一样的按钮风格都是经过不一样的类名来实现。
<button class="btn" type="button">基础按钮.btn</button> <button class="btn btn-default" type="button">默认按钮.btn-default</button> <button class="btn btn-primary" type="button">主要按钮.btn-primary</button> <button class="btn btn-success" type="button">成功按钮.btn-success</button> <button class="btn btn-warning" type="button">警告按钮.btn-warning</button> <button class="btn btn-danger" type="button">危险按钮.btn-danger</button> <button class="btn btn-link" type="button">连接按钮.btn-link</button>
3、按钮大小
在Bootstrap框架中,对于按钮的大小,也是能够定制的。
在Bootstrap框架中提供了三个类名来控制按钮大小:
<button class="btn btn-primary btn-lg" type="button">大型按钮.btn-lg</button> <button class="btn btn-primary" type="button">正常按钮</button> <button class="btn btn-primary btn-sm" type="button">小型按钮.btn-sm</button>
4、块状按钮
Bootstrap框架中提供了一个类名“.btn-block”。按钮使用这个类名就可让按钮充满整个容器,而且这个按钮不会有任何的padding和margin值。在实际当中,常把这种按钮称为块状按钮。
<button class="btn btn-primary btn-lg btn-block" type="button">大型按钮.btn-lg</button> <button class="btn btn-primary btn-block" type="button">正常按钮</button> <button class="btn btn-primary btn-sm btn-block" type="button">小型按钮.btn-sm</button> <button class="btn btn-primary btn-xs btn-block" type="button">超小型按钮.btn-xs</button>
5、按钮禁用状态
在Bootstrap框架中,要禁用按钮有两种实现方式:
方法1:在标签中添加disabled属性
方法2:在元素标签中添加类名“disabled”
二者的主要区别是:
“.disabled”样式不会禁止按钮的默认行为,好比说提交和重置行为等.
在元素标签中添加“disabled”属性的方法是能够禁止元素的默认行为的。
<button class="btn btn-primary btn-lg btn-block" type="button" disabled="disabled">经过disabled属性禁用按钮</button> <button class="btn btn-primary btn-block disabled" type="button">经过添加类名disabled禁用按钮</button>
在Bootstrap框架中对于图像的样式风格提供如下几种风格:
一、img-responsive:响应式图片,主要针对于响应式设计
二、img-rounded:圆角图片
三、img-circle:圆形图片
四、img-thumbnail:缩略图片
使用方法很是简单,只须要在<img>标签上添加对应的类名。
<img alt="140x140" src="http://placehold.it/140x140"> <img class="img-rounded" alt="140x140" src="http://placehold.it/140x140"> <img class="img-circle" alt="140x140" src="http://placehold.it/140x140"> <img class="img-thumbnail" alt="140x140" src="http://placehold.it/140x140"> <img class="img-responsive" alt="140x140" src="http://placehold.it/140x140">
在Bootstrap框架中是经过给元素添加“glyphicon”类名来实现,而后经过伪元素“:before”的“content”属性调取对应的icon编码:
<span class="glyphicon glyphicon-search"></span> <span class="glyphicon glyphicon-asterisk"></span> <span class="glyphicon glyphicon-plus"></span> <span class="glyphicon glyphicon-cloud"></span>
在网页中使用图标也很是的简单,在任何内联元素上应用所对应的样式便可: