日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

Bootstrap表單介紹

 WindySky 2016-05-03
Bootstrap來(lái)自 Twitter,是目前最受歡迎的前端框架。Bootstrap 是基于 HTML、CSS、JAVASCRIPT 的,它簡(jiǎn)潔靈活,使得 Web 開(kāi)發(fā)更加快捷。本文介紹一下Bootstrap的表單類型以及實(shí)現(xiàn)方法。

Bootstrap 提供了下列類型的表單布局:

- 垂直表單(默認(rèn))
- 內(nèi)聯(lián)表單
- 水平表單
- 垂直或基本表單

基本的表單結(jié)構(gòu)是 Bootstrap 自帶的,個(gè)別的表單控件自動(dòng)接收一些全局樣式。
下面列出了創(chuàng)建基本表單的步驟:

向父 <form> 元素添加 role="form"。
把標(biāo)簽和控件放在一個(gè)帶有 class .form-group 的 <div> 中。這是獲取最佳間距所必需的。
向所有的文本元素 <input>、<textarea> 和 <select> 添加 class .form-control。
<!DOCTYPE html>
<html>
<head>
   <title>Bootstrap 實(shí)例 - 基本表單</title>
   <link rel="stylesheet" href="http://apps./libs/bootstrap/3.3.0/css/bootstrap.min.css">
   <script src="http://apps./libs/jquery/2.1.1/jquery.min.js"></script>
   <script src="http://apps./libs/bootstrap/3.3.0/js/bootstrap.min.js"></script>
</head>
<body>

<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="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>

</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
結(jié)果如下所示:

這里寫圖片描述

內(nèi)聯(lián)表單
如果需要?jiǎng)?chuàng)建一個(gè)表單,它的所有元素是內(nèi)聯(lián)的,向左對(duì)齊的,標(biāo)簽是并排的,請(qǐng)向 <form> 標(biāo)簽添加 class .form-inline。
<!DOCTYPE html>
<html>
<head>
   <title>Bootstrap 實(shí)例 - 內(nèi)聯(lián)表單</title>
   <link rel="stylesheet" href="http://apps./libs/bootstrap/3.3.0/css/bootstrap.min.css">
   <script src="http://apps./libs/jquery/2.1.1/jquery.min.js"></script>
   <script src="http://apps./libs/bootstrap/3.3.0/js/bootstrap.min.js"></script>
</head>
<body>

<form class="form-inline" role="form">
   <div class="form-group">
      <label class="sr-only" for="name">名稱</label>
      <input type="text" class="form-control" id="name" 
         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>

</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
結(jié)果如下所示:

這里寫圖片描述

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


水平表單
水平表單與其他表單不僅標(biāo)記的數(shù)量上不同,而且表單的呈現(xiàn)形式也不同。如需創(chuàng)建一個(gè)水平布局的表單,請(qǐng)按下面的幾個(gè)步驟進(jìn)行:

向父 <form> 元素添加 class .form-horizontal。
把標(biāo)簽和控件放在一個(gè)帶有 class .form-group 的 <div> 中。
向標(biāo)簽添加 class .control-label。
<!DOCTYPE html>
<html>
<head>
   <title>Bootstrap 實(shí)例 - 水平表單</title>
   <link rel="stylesheet" href="http://apps./libs/bootstrap/3.3.0/css/bootstrap.min.css">
   <script src="http://apps./libs/jquery/2.1.1/jquery.min.js"></script>
   <script src="http://apps./libs/bootstrap/3.3.0/js/bootstrap.min.js"></script>
</head>
<body>

<form class="form-horizontal" role="form">
   <div class="form-group">
      <label for="firstname" class="col-sm-2 control-label">名字</label>
      <div class="col-sm-10">
         <input type="text" class="form-control" id="firstname" 
            placeholder="請(qǐng)輸入名字">
      </div>
   </div>
   <div class="form-group">
      <label for="lastname" class="col-sm-2 control-label">姓</label>
      <div class="col-sm-10">
         <input type="text" class="form-control" id="lastname" 
            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"> 請(qǐng)記住我
            </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>

</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
結(jié)果如下所示:

這里寫圖片描述

本文介紹了Bootstrap的表單類型和實(shí)現(xiàn)方法,下篇介紹表單支持的控件。

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約