全面解析Bootstrap表單使用方法(表單樣式)
一、基礎(chǔ)表單
<form > <div class="form-group"> <label>郵箱:</label> <input type="email" class="form-control" placeholder="請(qǐng)輸入您的郵箱地址"> </div> <div class="form-group"> <label >密碼</label> <input type="password" class="form-control" placeholder="請(qǐng)輸入您的郵箱密碼"> </div> <div class="checkbox"> <label> <input type="checkbox"> 記住密碼 </label> </div> <button type="submit" class="btn btn-default">進(jìn)入郵箱</button> </form>

表單除了這幾個(gè)元素之外,還有input、select、textarea等元素,在Bootstrap框架中,通過(guò)定制了一個(gè)類名`form-control`,也就是說(shuō),如果這幾個(gè)元素使用了類名“form-control”,將會(huì)實(shí)現(xiàn)一些設(shè)計(jì)上的定制效果。
1、寬度變成了100%
2、設(shè)置了一個(gè)淺灰色(#ccc)的邊框
3、具有4px的圓角
4、設(shè)置陰影效果,并且元素得到焦點(diǎn)之時(shí),陰影和邊框效果會(huì)有所變化
5、設(shè)置了placeholder的顏色為#999
二、水平表單
Bootstrap框架默認(rèn)的表單是垂直顯示風(fēng)格,但很多時(shí)候我們需要的水平表單風(fēng)格(標(biāo)簽居左,表單控件居右)。
<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="請(qǐng)輸入您的郵箱地址"> </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="請(qǐng)輸入您的郵箱密碼"> </div> </div> </form>

在Bootstrap框架中要實(shí)現(xiàn)水平表單效果,必須滿足以下兩個(gè)條件:
1、在<form>元素是使用類名".form-horizontal”。
2、配合Bootstrap框架的網(wǎng)格系統(tǒng)。
在<form>元素上使用類名".form-horizontal”主要有以下幾個(gè)作用:
1、設(shè)置表單控件padding和margin值。
2、改變“form-group”的表現(xiàn)形式,類似于網(wǎng)格系統(tǒng)的“row”。
三、內(nèi)聯(lián)表單
有時(shí)候我們需要將表單的控件都在一行內(nèi)顯示
<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="請(qǐng)輸入你的郵箱地址"> </div> <div class="form-group"> <label class="sr-only" for="exampleInputPassword2">密碼</label> <input type="password" class="form-control" id="exampleInputPassword2" placeholder="請(qǐng)輸入你的郵箱密碼"> </div> <button type="submit" class="btn btn-default">進(jìn)入郵箱</button> </form>

在Bootstrap框架中實(shí)現(xiàn)這樣的表單效果是輕而易舉的,你只需要在<form>元素中添加類名“.form-inline”即可。
如果你要在input前面添加一個(gè)label標(biāo)簽時(shí),會(huì)導(dǎo)致input換行顯示。如果你必須添加這樣的一個(gè)label標(biāo)簽,并且不想讓input換行,你需要將label標(biāo)簽也放在容器“form-group”中。
如果大家還想深入學(xué)習(xí),可以點(diǎn)擊這里進(jìn)行學(xué)習(xí),再為大家附兩個(gè)精彩的專題:Bootstrap學(xué)習(xí)教程 Bootstrap實(shí)戰(zhàn)教程
以上就是全面解析Bootstrap表單使用方法的第一篇,之后還有更多內(nèi)容會(huì)不斷更新,希望大家繼續(xù)關(guān)注。
- 基于Bootstrap+jQuery.validate實(shí)現(xiàn)Form表單驗(yàn)證
- Bootstrap實(shí)現(xiàn)登錄校驗(yàn)表單(帶驗(yàn)證碼)
- JS組件Form表單驗(yàn)證神器BootstrapValidator
- 全面解析Bootstrap表單使用方法(表單按鈕)
- 詳解Bootstrap創(chuàng)建表單的三種格式(一)
- 實(shí)用又漂亮的BootstrapValidator表單驗(yàn)證插件
- 基于bootstrap插件實(shí)現(xiàn)autocomplete自動(dòng)完成表單
- 基于jQuery.validate及Bootstrap的tooltip開(kāi)發(fā)氣泡樣式的表單校驗(yàn)組件思路詳解
- Bootstrap每天必學(xué)之表單
- 整理關(guān)于Bootstrap表單的慕課筆記
相關(guān)文章
淺談javascript中this在事件中的應(yīng)用
這篇文章主要介紹了淺談javascript中this在事件中的應(yīng)用實(shí)例,非常有助于我們對(duì)this關(guān)鍵字的理解,這里推薦給大家。2015-02-02
JavaScript檢測(cè)瀏覽器cookie是否已經(jīng)啟動(dòng)的方法
這篇文章主要介紹了JavaScript檢測(cè)瀏覽器cookie是否已經(jīng)啟動(dòng)的方法,實(shí)例分析了javascript操作cookie的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-02-02
那些項(xiàng)目中常見(jiàn)的TypeScript錯(cuò)誤總結(jié)
這篇文章主要給大家總結(jié)介紹了一些項(xiàng)目中常見(jiàn)的TypeScript錯(cuò)誤的相關(guān)資料,如果你想查看所有的錯(cuò)誤信息和錯(cuò)誤碼,可以瀏覽TypeScript的源代碼倉(cāng)庫(kù),當(dāng)然隨著?ts?版本的更新,官網(wǎng)也會(huì)逐漸增加更多新的類型錯(cuò)誤,需要的朋友可以參考下2022-03-03
解決uni-app報(bào)錯(cuò)Error:?read?EBADF?at?Pipe?.?onStreamRead...
這篇文章主要介紹了uni-app報(bào)錯(cuò)Error:?read?EBADF?at?Pipe?.?onStreamRead...解決方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08
使用p5.js實(shí)現(xiàn)動(dòng)態(tài)GIF圖片臨摹重現(xiàn)
這篇文章主要為大家詳細(xì)介紹了使用p5.js實(shí)現(xiàn)動(dòng)態(tài)GIF圖片臨摹重現(xiàn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-10-10
用JavaScript對(duì)JSON進(jìn)行模式匹配 (Part 2 - 實(shí)現(xiàn))
在上一篇文章里,我們完成了 Dispatcher 類的接口設(shè)計(jì),現(xiàn)在我們就來(lái)考慮一下如何實(shí)現(xiàn)這個(gè)類。2010-07-07
JS?for?in遍歷對(duì)象順序不對(duì)解決辦法
最近使用for-in語(yǔ)句遍歷對(duì)象屬性時(shí)發(fā)現(xiàn)遍歷順序并非屬性構(gòu)建順序,這篇文章主要給大家介紹了關(guān)于JS?for?in遍歷對(duì)象順序不對(duì)的解決辦法,需要的朋友可以參考下2023-11-11

