Bootstrap关于表单控件(Radio,CheckBox)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Bootstrap关于表单控件(Radio,CheckBox)
表单控件(复选框checkbox和单选择按钮radio)
Bootstrap框架中checkbox和radio有点特殊,Bootstrap针对他们做了⼀些特殊化处理,主要是checkbox和radio与label标签配合使⽤会出现⼀些⼩问题(最头痛的是对齐问题)。
使⽤Bootstrap框架,开发⼈员⽆需考虑太多,只需要按照下⾯的⽅法使⽤即可。
<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>
运⾏效果如下或查看右侧结果窗⼝(案例1):
从上⾯的⽰例,我们可以得知: 1、不管是checkbox还是radio都使⽤label包起来了 2、checkbox连同label标签放置在⼀个名
为“.checkbox”的容器内 3、radio连同label标签放置在⼀个名为“.radio”的容器内在Bootstrap框架中,主要借助“.checkbox”和“.radio”样式,来处理复选框、单选按钮与标签的对齐⽅式。
有时候,为了布局的需要,将复选框和单选按钮需要⽔平排列。
Bootstrap框架也做了这⽅⾯的考虑: 1、如果checkbox需要⽔平排列,只需要在label标签上添加类名“checkbox-inline” 2、如果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>
运⾏效果如下或查看右侧结果窗⼝:。