Bootstrap每天必学之表单

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

1.基本案例
2.内联表单
3.水平排列的表单
4.被支持的控件
5.静态控件
6.控件状态
7.控件尺寸
8.帮助文本

基本案例
 单独的表单控件会被自动赋予一些全局样式。所有设置了.form-control的<input>、<textarea>和<select>元素都将被默认设置为width: 100%;。将label和前面提到的这些控件包裹在.form-group中可以获得最好的排列。

<form role="form"> <div> <label for="exampleInputEmail1">Email address</label> <input type="email" placeholder="Enter email"> </div> <div> <label for="exampleInputPassword1">Password</label> <input type="password" placeholder="Password"> </div> <div> <label for="exampleInputFile">File input</label> <input type="file"> <p>Example block-level help text here.</p> </div> <div> <label> <input type="checkbox"> Check me out </label> </div> <button type="submit">Submit</button> </form>

Bootstrap每天必学之表单

两个文本框的宽度的确为100%。并且有三个form-group。
内联表单
为左对齐和inline-block级别的控件设置.form-inline,可以将其排布的更紧凑。
需要设置宽度:在Bootstrap中,input、select和textarea默认被设置为100%宽度。为了使用内联表单,你需要专门为使用到的表单控件设置宽度。

 一定要设置label:如果你没有为每个输入控件设置label,屏幕阅读器将无法正确识读。对于这些内联表单,你可以通过为label设置.sr-only已将其隐藏。

<form role="form"> <div> <label for="exampleInputEmail2">Email address</label> <input type="email" placeholder="Enter email"> </div> <div> <label for="exampleInputPassword2">Password</label> <input type="password" placeholder="Password"> </div> <div> <label> <input type="checkbox"> Remember me </label> </div> <button type="submit">Sign in</button> </form>

Bootstrap每天必学之表单

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

<form role="form"> <div> <label for="inputEmail3">Email</label> <div> <input type="email" placeholder="Email"> </div> </div> <div> <label for="inputPassword3">Password</label> <div> <input type="password" placeholder="Password"> </div> </div> <div> <div> <div> <label> <input type="checkbox"> Remember me </label> </div> </div> </div> <div> <div> <button type="submit">Sign in</button> </div> </div> </form>

Bootstrap每天必学之表单

被支持的控件
在表单布局案例中展示了其所支持的标准表单控件。
Input
大部分表单控件、文本输入域控件。包括HTML5支持的所有类型:text、password、datetime、datetime-local、date、month、time、week、number、email、url、search、telcolor。
注意:有正确设置了type的input控件才能被赋予正确的样式。
文本框示例

复制代码 代码如下:

<input type="text" placeholder="Text input">

Bootstrap每天必学之表单

Textarea
支持多行文本的表单控件。可根据需要改变rows属性。  

<h1>textarea</h1> <textarea rows="3"></textarea>

Bootstrap每天必学之表单

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgzdsf.html