1. 表單
表單是html網(wǎng)頁交互很重要的部分,同時(shí)也是BootSTrap框架中的核心內(nèi)容,表單提供了豐富的樣式(基礎(chǔ)、內(nèi)聯(lián)、橫向)
表單的元素
input textarea select checkbox radio(checkbox和radio是input的特殊類型)
其他標(biāo)簽
form fieldset legend
1.1.基礎(chǔ)表單
<!--基礎(chǔ)表單:1.向父 <form> 元素添加 role="form"。2.把標(biāo)簽label和控件放在一個(gè)帶有 class .form-group 的 <div> 中。這是獲取最佳間距所必需的。因?yàn)閒orm-group提供了margin3.向所有的文本元素 <input>、<textarea> 和 <select> 添加 class .form-control。--><form role="form"> <fieldset> <legend>用戶登錄</legend> <div class="form-group"> <label for="name">姓名</label> <input type="text" class="form-control" id="name" placeholder="請(qǐng)輸入名稱"> </div> <div class="form-group"> <label for="psd">密碼</label> <input type="text" class="form-control" id="psd" placeholder="請(qǐng)輸入密碼"> </div> <div class="checkbox"> <label><input type="checkbox">記住密碼</label> </div> <button type="submit" class="btn btn-default">登錄</button> </fieldset></form>
1.2.內(nèi)聯(lián)表單
<!-- 內(nèi)聯(lián)表單: 如果需要?jiǎng)?chuàng)建一個(gè)表單,它的所有元素是內(nèi)聯(lián)的,向左對(duì)齊的,標(biāo)簽是并排的,請(qǐng)向 <form> 標(biāo)簽添加 class .form-inline --> <form role="form" class="form-inline"> <fieldset> <legend>用戶登錄</legend> <div class="form-group"> <label for="name">姓名</label> <input type="text" class="form-control" id="name" placeholder="請(qǐng)輸入名稱"> </div> <div class="form-group"> <label for="psd">密碼</label> <input type="text" class="form-control" id="psd" placeholder="請(qǐng)輸入密碼"> </div> <div class="checkbox"> <label><input type="checkbox">記住密碼</label> </div> <button type="submit" class="btn btn-default">登錄</button> </fieldset> </form>
1.3.橫向表單
<!-- 橫向表單: 1.向父 <form> 元素添加 class .form-horizontal。 2.把標(biāo)簽和控件放在一個(gè)帶有 class .form-group 的 <div> 中。 3.向標(biāo)簽添加 class .control-label。 4.要實(shí)現(xiàn)橫向表單,還要用柵格類--> <form role="form" class="form-horizontal"> <fieldset> <legend>用戶登錄</legend> <div class="form-group"> <label class="control-label col-lg-1" for="name">姓名</label> <div class="col-lg-10"> <input type="text" class="form-control" id="name" placeholder="請(qǐng)輸入名稱"> </div> </div> <div class="form-group"> <label class="control-label col-lg-1" for="psd">密碼</label> <div class="col-lg-10"> <input type="text" class="form-control" id="psd" placeholder="請(qǐng)輸入密碼"> </div> </div> </fieldset> </form>
1.4.表單控件
input元素:
使用input元素的時(shí)候,必須聲明type類型,否則可能引起問題。
select元素:
多行選擇設(shè)置multiple=”multiple”
textarea元素:
textarea元素定義了rows數(shù)字即可定義大文本框的高度,cols寬度。但是textarea應(yīng)用了form-control央視,則cols無效。
checkbox和radio(是兩個(gè)特殊的type)
注意使用的時(shí)候,每個(gè)input外部用label包住,并且在最外層用容器元素寶珠,并應(yīng)用相應(yīng)的.checkbox和.radio樣式。
//使用<div class="checkbox"> <label><input type="checkbox">學(xué)習(xí)前端</label></div><div class="radio"> <label><input type="radio" name="optionsRadios" value="male">男生</label></div><div class="radio"> <label><input type="radio" name="optionsRadios" value="female">女生</label></div>
//源碼//讓單選框和復(fù)選框都能左右和上下居中.radio,.checkbox { position: relative; display: block; margin-top: 10px; margin-bottom: 10px;}//內(nèi)部有l(wèi)abel的話,內(nèi)聯(lián)顯示.radio label,.checkbox label { min-height: 20px; padding-left: 20px; margin-bottom: 0; font-weight: normal; cursor: pointer;}同時(shí)可以內(nèi)聯(lián)顯示,在labelshang添加checkbox-inline或者radio-inline
1.5.空間狀態(tài)
焦點(diǎn)狀態(tài)、禁用狀態(tài)、驗(yàn)證提示狀態(tài)
焦點(diǎn)狀態(tài):
當(dāng)輸入框 input 接收到 :focus 時(shí),輸入框的輪廓會(huì)被移除,同時(shí)應(yīng)用 box-shadow。
禁用狀態(tài):
對(duì) 添加 disabled 屬性來禁用 內(nèi)的所有控件。
驗(yàn)證提示狀態(tài):
Bootstrap 包含了錯(cuò)誤、警告和成功消息的驗(yàn)證樣式。只需要對(duì)父元素簡單地添加適當(dāng)?shù)?class(.has-warning、 .has-error 或 .has-success)即可使用驗(yàn)證狀態(tài)。
主站蜘蛛池模板:
南康市|
永靖县|
新化县|
全椒县|
江源县|
宜君县|
东山县|
西乌|
兴山县|
汽车|
涿鹿县|
遵化市|
资源县|
弋阳县|
乌恰县|
调兵山市|
揭阳市|
六盘水市|
云浮市|
宣恩县|
修武县|
依兰县|
额尔古纳市|
长寿区|
晋江市|
双峰县|
盘锦市|
称多县|
老河口市|
水富县|
搜索|
行唐县|
兰西县|
渝中区|
诸暨市|
襄垣县|
新化县|
嵊州市|
阳新县|
罗源县|
清苑县|