首页 > 其他分享 >深入理解BootStrap -- 表单5

深入理解BootStrap -- 表单5

时间:2022-12-14 15:34:38浏览次数:82  
标签:控件 form -- BootStrap 表单 样式 设置 input


前言

本文主要讲解的是表单,这个其实对于做过网站的人来说,并不陌生,而且可以说是最为常用的提交数据的Form表单。本文主要来讲解一下内容:

​1.基本案例​

​2.内联表单​

​3.水平排列的表单​

​4.被支持的控件​

​5.静态控件​

​6.控件状态​

​7.控件尺寸​

​8.帮助文本​

​9.总结​

基本案例

​.form-control​​的​​<input>​​、​​<textarea>​​和​​<select>​​元素都将被默认设置为​​width: 100%;​​。将label和前面提到的这些控件包裹在​​.form-group​​中可以获得最好的排列。

<form role="form">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label>
<input type="file" id="exampleInputFile">
<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" class="btn btn-default">Submit</button>
</form>



深入理解BootStrap -- 表单5_bootstrap

       两个文本框的宽度的确为100%。并且有三个form-group。

内联表单

​.form-inline​​,可以将其排布的更紧凑。

需要设置宽度:在Bootstrap中,input、select和textarea默认被设置为100%宽度。为了使用内联表单,你需要专门为使用到的表单控件设置宽度。

 

.sr-only已将其隐藏。


<form class="form-inline" role="form">
<div class="form-group">
<label class="sr-only" for="exampleInputEmail2">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail2" placeholder="Enter email">
</div>
<div class="form-group">
<label class="sr-only" for="exampleInputPassword2">Password</label>
<input type="password" class="form-control" id="exampleInputPassword2" placeholder="Password">
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
<button type="submit" class="btn btn-default">Sign in</button>
</form>



深入理解BootStrap -- 表单5_bootstrap_02

水平排列的表单

​.form-horizontal​​,并使用Bootstrap预置的栅格class可以将label和控件组水平并排布局。这样做将改变​​.form-group​​的行为,使其表现为栅格系统中的行(row),因此就无需再使用​​.row​​了。

<form class="form-horizontal" role="form">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Sign in</button>
</div>
</div>
</form>



深入理解BootStrap -- 表单5_控件_03

被支持的控件

在表单布局案例中展示了其所支持的标准表单控件。

Input

​text​​、​​password​​、​​datetime​​、​​datetime-local​​、​​date​​、​​month​​、​​time​​、​​week​​、​​number​​、​​email​​、​​url​​、​​search​​、​​tel​​和​​color​​。

注意:有正确设置了type的input控件才能被赋予正确的样式。

文本框示例


<input type="text" class="form-control" placeholder="Text input">



深入理解BootStrap -- 表单5_表单_04

Textarea

​rows​​属性。

 


<h1>textarea</h1>
<textarea class="form-control" rows="3"></textarea>



深入理解BootStrap -- 表单5_Email_05

Checkbox 和 radio

Checkbox用于选择列表中的一个或多个选项,而radio用于从多个选项中只选择一个。

默认外观(堆叠在一起)


<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="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>



深入理解BootStrap -- 表单5_Email_06

Inline checkboxes

​.checkbox-inline​​ 或 ​​.radio-inline​​应用到一系列的checkbox或radio控件上,可以使这些控件排列在一行。

<label class="checkbox-inline">
<input type="checkbox" id="inlineCheckbox1" value="option1"> 1
</label>
<label class="checkbox-inline">
<input type="checkbox" id="inlineCheckbox2" value="option2"> 2
</label>
<label class="checkbox-inline">
<input type="checkbox" id="inlineCheckbox3" value="option3"> 3
</label>


 


深入理解BootStrap -- 表单5_控件_07

 

同理Radio是一样的,只需要添加一下样式即可。

Select


<select class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>

<select multiple class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>



深入理解BootStrap -- 表单5_控件_08

静态控件

​<p>​​元素添加​​.form-control-static​​即可。

<form class="form-horizontal" role="form">
<div class="form-group">
<label class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<p class="form-control-static">[email protected]</p>
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword" placeholder="Password">
</div>
</div>
</form>



深入理解BootStrap -- 表单5_控件_09

控件状态

控件状态

  通过为控件和label设置一些基本状态,可以为用户提供回馈。

​outline​​样式,并对其​​:focus​​状态赋予了​​box-shadow​​样式。

<input class="form-control" id="focusedInput" type="text" value="This is focused...">



深入理解BootStrap -- 表单5_控件_10

​disabled​​属性可以防止用户输入,并能改变一点外观,使其更直观。

<input class="form-control" id="disabledInput" type="text" placeholder="Disabled input here..." disabled>



深入理解BootStrap -- 表单5_表单_11

​<fieldset>​​设置​​disabled​​属性可以禁用​​<fieldset>​​中包含的所有控件。

<a>标签的链接功能不受影响

<a class="btn btn-default">按钮的外观,并不能禁用其功能。建议自己通过JavaScript代码禁用链接功能。

跨浏览器兼容性

<fieldset>并不支持disabled属性。因此建议在这些浏览器上通过JavaScript代码来禁用fieldset


<form role="form">
<fieldset disabled>
<div class="form-group">
<label for="disabledTextInput">Disabled input</label>
<input type="text" id="disabledTextInput" class="form-control" placeholder="Disabled input">
</div>
<div class="form-group">
<label for="disabledSelect">Disabled select menu</label>
<select id="disabledSelect" class="form-control">
<option>Disabled select</option>
</select>
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Can't check this
</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</fieldset>
</form>



深入理解BootStrap -- 表单5_控件_12

  可将鼠标移到各个控件上进行查看效果。

校验状态

​.has-warning​​、​​.has-error​​或​​.has-success​​到这些控件的父元素即可。任何包含在此元素之内的​​.control-label​​、​​.form-control​​和​​.help-block​​都将接受这些校验状态的样式。

<div class="form-group has-success">
<label class="control-label" for="inputSuccess">Input with success</label>
<input type="text" class="form-control" id="inputSuccess">
</div>
<div class="form-group has-warning">
<label class="control-label" for="inputWarning">Input with warning</label>
<input type="text" class="form-control" id="inputWarning">
</div>
<div class="form-group has-error">
<label class="control-label" for="inputError">Input with error</label>
<input type="text" class="form-control" id="inputError">
</div>



深入理解BootStrap -- 表单5_bootstrap_13

控件尺寸

 

​.input-lg​​之类的class可以为控件设置高度,通过​​.col-lg-*​​之类的class可以为控件设置宽度。

高度尺寸

创建大一些或小一些的表单控件以匹配按钮尺寸。


<input class="form-control input-lg" type="text" placeholder=".input-lg">
<input class="form-control" type="text" placeholder="Default input">
<input class="form-control input-sm" type="text" placeholder=".input-sm">

<select class="form-control input-lg">...</select>
<select class="form-control">...</select>
<select class="form-control input-sm">...</select>



深入理解BootStrap -- 表单5_控件_14

调整列尺寸

用栅格系统中的列包裹input或其任何父元素,都可很容易的为其设置宽度。


<div class="row">
<div class="col-xs-2">
<input type="text" class="form-control" placeholder=".col-xs-2">
</div>
<div class="col-xs-3">
<input type="text" class="form-control" placeholder=".col-xs-3">
</div>
<div class="col-xs-4">
<input type="text" class="form-control" placeholder=".col-xs-4">
</div>
</div>



深入理解BootStrap -- 表单5_bootstrap_15

帮助文本

 用于表单控件的块级帮助文本。


<span class="help-block">自己独占一行或多行的块级帮助文本。</span>


总结

 本篇文章主要讲解表单中各种控件的样式控制。其中也有看到按钮的简单样式使用,下一篇文章将重点来讲解按钮的样式。

标签:控件,form,--,BootStrap,表单,样式,设置,input
From: https://blog.51cto.com/u_15912341/5937208

相关文章

  • Linux man命令手册使用方法,man和man5区别
    1、https://www.modb.pro/db/4464931.man手册页简介man手册页(manualpages,“手册”),是类UNIX系统最重要的手册工具。多数Linux发行版都预装了它。Linux提供了丰富的帮......
  • multer 库的使用
    multer库的使用原生表单上传<!--必须要指定enctype值,因为默认是application/x-www-form-urlencoded--><formaction="http://localhost:3000/test"method="pos......
  • EhCache的介绍
    ehcache是一个非常轻量级的缓存实现,而且从1.2之后就支持了集群,而且是hibernate默认的缓存provider。EhCache是一个纯Java的进程内缓存框架,具有快速、精干等特点,是Hibernat......
  • SpringBoot入门:Hello World(一)
       跟随SpringBoot的文档(http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-documentation)学习,前后几章关联才调通代码,煞是痛苦,在......
  • [Typescript] Key in union type
    Let'ssaywewanttoextractqueryparamfromstring:typeUserPath="/users/:id";typeUserOrganisationPath="/users/:id/organisations/:organisationId";So......
  • 从SQL脚本中提取表小工具
     gspdemo.exeGeneralSQLParserDemo    ......
  • 深入理解BootStrap -- 按钮6
    前言本文主要讲解的是按钮的样式。​​1.选项​​​​2.尺寸​​​​3.活动状态​​​​4.禁用状态​​​​5.可做按钮使用的Html标签​​​​6.总结​​选项 ......
  • django.db.utils.DataError: (1406, "Data too long for column 'password' at row 1"
    问题: pythonmanage.pycreatesuperuser 无法创建超级用户报错:django.db.utils.DataError:(1406,"Datatoolongforcolumn'password'atrow1")问题原因:用户模......
  • eclipse运行java.lang.OutOfMemoryError: PermGen space解决方法
    一、在window下eclipse里面Server挂的是tomcat6,一开始还是以为,tomcat配置的问题,后面发现,配置了tomcat里面的catalina.bat文件,加入 setJAVA_OPTS=-Xms512m-Xmx1024m-XX......
  • javaweb之文件上传总结
    一。文件上传:是指允许客户将本地文件,上传到服务器端 常见的应用:上传照片、上传新闻图片、上传附件 文件上传编程基本步骤: 1、在用户页面中添加上传输入项(客户端页......