欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

深入學(xué)習(xí)Bootstrap表單

 更新時(shí)間:2016年12月13日 11:39:21   作者:Tiramisu_C  
這篇文章主要為大家詳細(xì)介紹了Bootstrap表單的基礎(chǔ)知識(shí),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文知識(shí)點(diǎn)借鑒來(lái)自http://www.runoob.com/bootstrap/bootstrap-forms.html,里面寫的比較詳細(xì)還給出了例子,這里總結(jié)一下重點(diǎn)方便記憶。

一、表單布局

1.垂直表單(默認(rèn))

        向父 <form> 元素添加 role="form"。
        把標(biāo)簽和控件放在一個(gè)帶有 class .form-group 的 <div> 中。這是獲取最佳間距所必需的。
        向所有的文本元素 <input>、<textarea> 和 <select> 添加 class .form-control。

<form action="#" role="form"> 
  <div class="form-group"> 
   <lable>姓名:<input class="form-control" type="text"/></lable> 
   <lable>性別:<input class="form-control" type="text"/></lable> 
  </div> 
 </form> 

2.內(nèi)聯(lián)表單

向 <form> 標(biāo)簽添加 class .form-inline;       
默認(rèn)情況下,Bootstrap 中的 input、select 和 textarea 有 100% 寬度。在使用內(nèi)聯(lián)表單時(shí),您需要在表單控件上設(shè)置一個(gè)寬度。
使用 class .sr-only,您可以隱藏內(nèi)聯(lián)表單的標(biāo)簽。

 3.水平表單        

    向父 <form> 元素添加 class .form-horizontal。       
    把標(biāo)簽和控件放在一個(gè)帶有 class .form-group 的 <div> 中。       
    向標(biāo)簽添加 class .control-label。

<form action="#" role="form" class="form-horizontal"> 
  <div class="form-group"> 
   <lable class="control-label col-lg-2">姓名:</lable> 
   <div class=" col-lg-10"><input class="form-control" type="text"/></div> 
 
   <lable class="control-label col-lg-2">性別:</lable> 
   <div class="col-lg-10"><input class="form-control " type="text"/></div> 
  </div> 
 </form> 

 二、支持的表單控件

1.輸入框(Input)

<lable>姓名:<input class="form-control" type="text"/></lable> 

2.文本框(Textarea)  可改變 rows 屬性

<div class="form-group"> 
  <textarea rows="8" class="form-control"> 
 
   </textarea> 
 
 </div> 

3.復(fù)選框(Checkbox)和單選框(Radio)        
    當(dāng)創(chuàng)建表單時(shí),如果您想讓用戶從列表中選擇若干個(gè)選項(xiàng)時(shí),請(qǐng)使用 checkbox。如果您限制用戶只能選擇一個(gè)選項(xiàng),請(qǐng)使用 radio。       
    對(duì)一系列復(fù)選框和單選框使用 .checkbox-inline 或 .radio-inline class,控制它們顯示在同一行上。

<div class="checkbox-inline"> 
    <lable class="control-label"><input type="checkbox"/>籃球</lable> 
   </div> 
   <div class="checkbox-inline"> 
    <lable class="control-label"><input type="checkbox"/>音樂(lè)</lable> 
   </div> 
   <div class="checkbox-inline"> 
    <lable class="control-label"><input type="checkbox"/>繪畫</lable> 
   </div> 
   <div class="radio"> 
    <lable><input type="radio"/>男</lable> 
   </div> 
   <div class="radio"> 
    <lable><input type="radio"/>女</lable> 
   </div> 

 4.選擇框(Select)        

    使用 <select> 展示列表選項(xiàng),通常是那些用戶很熟悉的選擇列表,比如州或者數(shù)字。       
    使用 multiple="multiple" 允許用戶選擇多個(gè)選項(xiàng)。

<div class="form-group"> 
     <select name="" id="" class="form-control" multiple> 
      <option value="">1</option> 
      <option value="">1</option> 
      <option value="">1</option> 
      <option value="">1</option> 
      <option value="">1</option> 
     </select> 
    </div> 

 5.靜態(tài)控件        

當(dāng)您需要在一個(gè)水平表單內(nèi)的表單標(biāo)簽后放置純文本時(shí),請(qǐng)?jiān)?<p> 上使用 class .form-control-static。

<div class="form-group"> 
  <label class="col-sm-2 control-label">Email</label> 
  <div class="col-sm-10"> 
  <p class="form-control-static">email@example.com</p> 
  </div> 
 </div> 

三、表單控件狀態(tài)

1.輸入框焦點(diǎn)        

當(dāng)輸入框 input 接收到 :focus 時(shí),輸入框的輪廓會(huì)被移除,同時(shí)應(yīng)用 box-shadow。   

2.禁用的輸入框 input        

如果您想要禁用一個(gè)輸入框 input,只需要簡(jiǎn)單地添加 disabled 屬性,這不僅會(huì)禁用輸入框還,會(huì)改變輸入框的樣式以及當(dāng)鼠標(biāo)的指針懸停在元素上時(shí)鼠標(biāo)指針的樣式。

<div> 
  <lable>姓名:<input type="text" disabled class="form-control"/></lable> 
 </div> 

3.禁用的字段集 fieldset        

對(duì) <fieldset> 添加 disabled 屬性來(lái)禁用 <fieldset> 內(nèi)的所有控件。

4.驗(yàn)證狀態(tài)        

Bootstrap 包含了錯(cuò)誤、警告和成功消息的驗(yàn)證樣式。只需要對(duì)父元素簡(jiǎn)單地添加適當(dāng)?shù)腸lass(.has-warning、 .has-error 或 .has-success)即可使用驗(yàn)證狀態(tài)。

<div class="has-error"> 
  <lable class="control-label"> 
   姓名:<input type="text" class="form-control" placeholder="has-error"/> 
  </lable> 
</div> 
<div class="has-warning"> 
  <lable class="control-label"> 
   姓名:<input type="text" class="form-control" placeholder="has-warning"/> 
  </lable> 
</div> 

 5.表單控件大小    

分別使用 class .input-lg(或.input-sm) 和 .col-lg-* 來(lái)設(shè)置表單的高度和寬度

<div class="form-group"> 
  姓名:<input type="text" class="form-control input-lg" placeholder="input-lg"/> 
  姓名:<input type="text" class="form-control input-sm" placeholder="input-sm"/> 
  姓名:<input type="text" class="form-control " placeholder="normal"/> 
</div>

 6.表單幫助文本

Bootstrap 表單控件可以在輸入框 input 上有一個(gè)塊級(jí)幫助文本。    為了添加一個(gè)占用整個(gè)寬度的內(nèi)容塊,請(qǐng)?jiān)?<input> 后使用 .help-block。

<div class="form-grounp"> 
  <input type="text"/> 
  <span class="help-block"> 
   Bootstrap 表單控件可以在輸入框 input 上有一個(gè)塊級(jí)幫助文本。 
  </span> 
</div> 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論