bootstrap表單

  • 垂直表單(默認(rèn))
  • 內(nèi)聯(lián)表單
  • 水平表單

垂直表單

也稱基本表單
基本的表單結(jié)構(gòu)是 bootstrap 自帶的
創(chuàng)建基本表單的步驟:

  • 向父 <form> 元素添加 role="form"。
  • 把標(biāo)簽和控件放在一個(gè)帶有 class .form-group 的 <div> 中。這是獲取最佳間距所必需的。
  • 向所有的文本元素 <input>、<textarea> 和 <select> 添加 class ="form-control" 。
 <form role="form">
    <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="tel">電話</label>
         <input type="text" class="form-control" id="tel" placeholder="請(qǐng)輸入電話">
    </div>
    <div class="form-group">
        <label for="inputfile">文件輸入</label>
         <input type="file" id="inputfile">
         <p class="help-block">這里是塊級(jí)幫助文本的實(shí)例。</p>
    </div>
    <div class="checkbox">
      <label>
         <input type="checkbox">請(qǐng)打勾
      </label>
      </div>
      <button type="submit" class="btn btn-default">提交</button>
</form>

效果:

Paste_Image.png

使用class .help-block來(lái)顯示表單提示信息

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

內(nèi)聯(lián)表單即所有元素是內(nèi)聯(lián)的,向左對(duì)齊的,并排體現(xiàn)
在 <form> 標(biāo)簽添加 class .form-inline

<form class="form-inline" role="form">
  <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="tel">電話</label>
   <input type="text" class="form-control" id="tel" placeholder="請(qǐng)輸入電話">
  </div>
  <div class="form-group">
    <label class="sr-only" for="inputfile">文件輸入</label>
    <input type="file" id="inputfile">
  </div>
  <div class="checkbox">
    <label>
       <input type="checkbox">請(qǐng)打勾
    </label>
  </div>
  <button type="submit" class="btn btn-default">提交</button>
</form>

效果:


Paste_Image.png
水平表單

水平表單風(fēng)格(標(biāo)簽居左,表單控件居右)
創(chuàng)建步驟:

  • 在 <form> 標(biāo)簽添加 class .form-horizontal
  • 把標(biāo)簽和控件放在一個(gè)帶有 class .form-group 的 <div> 中。
  • 向標(biāo)簽添加 class .control-label。
<form class="form-horizontal" role="form">
    <div class="form-group">
       <label for="name" class="col-sm-2 control-label">昵稱 </label>
           <div class="col-sm-10">
              <input type="text" class="form-control" id="name" placeholder="請(qǐng)輸入昵稱">
           </div>
    </div>
    <div class="form-group">
       <label for="inputPassword" class="col-sm-2 control-label">密碼</label>
          <div class="col-sm-10">
            <input type="password" class="form-control" id="inputPassword" placeholder="請(qǐng)輸入密碼">
           </div>
    </div>
    <div class="form-group">
       <div class="col-sm-offset-2 col-sm-10">
          <div class="checkbox">
            <label>
             <input type="checkbox">記住密碼
            </label>
          </div>
       </div>
    </div>
    <div class="form-group">
       <div class="col-sm-offset-2 col-sm-10">
          <button type="submit" class="btn btn-default">登錄</button>
       </div>
    </div>
</form>

效果:

Paste_Image.png

代碼中用到網(wǎng)格標(biāo)示col-sm-2
bootstrap 包含了一個(gè)響應(yīng)式的、移動(dòng)設(shè)備優(yōu)先的、不固定的網(wǎng)格系統(tǒng),可以隨著設(shè)備或視口大小的增加而適當(dāng)?shù)財(cái)U(kuò)展到 12 列。
bootstrap網(wǎng)格的基本結(jié)構(gòu)

<div class="container">
   <div class="row">
      <div class="col-*-*"></div>
      <div class="col-*-*"></div>      
   </div>
</div>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • Bootstrap是什么? 一套易用、優(yōu)雅、靈活、可擴(kuò)展的前端工具集--BootStrap。GitHub上介紹 的...
    凜0_0閱讀 10,935評(píng)論 3 184
  • 表單控件 文本域:與原始文本域使用方式相同,可以通過rows定義高度,設(shè)置cols定義寬度。但如果在文本域中添加了...
    子非魚666閱讀 696評(píng)論 0 2
  • 基本實(shí)例 單獨(dú)的表單控件會(huì)被自動(dòng)賦予一些全局樣式。所有設(shè)置了 .form-control 類的 、 和 元...
    葶寳寳閱讀 1,115評(píng)論 0 6
  • 表單布局 垂直表單(默認(rèn)) 內(nèi)聯(lián)表單 水平表單 垂直表單或基本表單 基本的表單結(jié)構(gòu)是 Bootstrap 自帶的,...
    秋楓殘紅閱讀 224評(píng)論 0 1
  • 一、表單 1. 基本樣式 //實(shí)現(xiàn)基本的表單樣式 電子郵件 密碼 注:只有正確設(shè)置了輸入框的ty...
    lilyping閱讀 3,179評(píng)論 0 7