6.9.5 表单控件的大小
如果要单独设置表单控件的高度,则可通过如下样式来设置。
| 样式 | 描述 | 
| .input-lg | 设置”大”的控件。 | 
| .input-sm | 设置”小”的控件。 | 
|  |  | 
| ## 程序示例 单独设置表单控件的高度 ## |  | 
| 例如如下代码用于控制表单控件的大小。 |  | 
| | 12
 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
 44
 45
 46
 
 | <!DOCTYPE html><html>
 
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title> 设置表单控件高度 </title>
 <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
 <link rel="stylesheet" href="../bootstrap/css/bootstrap-theme.min.css">
 <style type="text/css">
 input,
 select {
 margin-bottom: 10px;
 }
 </style>
 </head>
 
 <body>
 <div class="container">
 <input type="text" class="form-control input-lg" id="a" placeholder=".input-lg">
 <input type="text" class="form-control" id="b" placeholder="默认高度">
 <input type="text" class="form-control input-sm" id="c" placeholder=".input-sm">
 <select type="text" class="form-control input-lg" id="d">
 <option value="a">.input-lg-1</option>
 <option value="a">.input-lg-2</option>
 <option value="a">.input-lg-3</option>
 <option value="a">.input-lg-4</option>
 </select>
 <select type="text" class="form-control" id="e">
 <option value="a">.默认大小1</option>
 <option value="a">.默认大小2</option>
 <option value="a">.默认大小3</option>
 <option value="a">.默认大小4</option>
 </select>
 <select type="text" class="form-control input-sm" id="f">
 <option value="a">.input-sm-1</option>
 <option value="a">.input-sm-2</option>
 <option value="a">.input-sm-3</option>
 <option value="a">.input-sm-4</option>
 </select>
 </div>
 <script type="text/javascript" src="../jquery-3.1.1.js"></script>
 <script type="text/javascript" src="../bootstrap/js/bootstrap.min.js"></script>
 </body>
 
 </html>
 
 | 
 |  | 
设置水平表单整个控件的高度或字体
对于水平表单,如果要设置整个控件组件(包括控件以及该控件对应的<label>元素)的高度和字体,可通过如下样式来设置。
| 样式 | 描述 | 
| .form-group-lg | 设置”大”的控件和 label。 | 
| .form-group-sm | 设置”小”的控件和 label。 | 
|  |  | 
| ### 程序示例 ### |  | 
| 例如如下代码用于控制水平表单中控件的大小。 |  | 
| | 12
 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
 
 | <!DOCTYPE html><html>
 
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title> 设置表单控件高度 </title>
 <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
 <link rel="stylesheet" href="../bootstrap/css/bootstrap-theme.min.css">
 </head>
 
 <body>
 <div class="container">
 
 <form action="http://www.fkit.org" class="form-horizontal">
 
 
 <div class="form-group form-group-lg">
 <label for="a" class="col-sm-3 control-label">用户名</label>
 <div class="col-sm-9">
 
 <input type="text" class="form-control" id="a" placeholder=".form-group-lg">
 </div>
 </div>
 <div class="form-group">
 <label for="b" class="col-sm-3 control-label">用户名</label>
 <div class="col-sm-9">
 <input type="text" class="form-control" id="b" placeholder="正常大小">
 </div>
 </div>
 <div class="form-group form-group-sm">
 <label for="c" class="col-sm-3 control-label">用户名</label>
 <div class="col-sm-9">
 <input type="text" class="form-control" id="c" placeholder=".form-group-sm">
 </div>
 </div>
 </form>
 </div>
 <script type="text/javascript" src="../jquery-3.1.1.js"></script>
 <script type="text/javascript" src="../bootstrap/js/bootstrap.min.js"></script>
 </body>
 
 </html>
 
 | 
 |  | 
如何设置表单控件的宽度
默认情况下,表单控件的宽度总是100%,因此开发者通常不能直接控制该表单控件的宽度,但实际上可以将表单控件放入网格布局的单元格中,再通过设置单元格所占的列宽来控制表单控件的宽度。
例如如下代码即可用于控制表单控件的宽度。
| 12
 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
 44
 45
 46
 47
 48
 49
 
 | <!DOCTYPE html><html>
 
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title> 设置控件宽度 </title>
 <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
 <link rel="stylesheet" href="../bootstrap/css/bootstrap-theme.min.css">
 </head>
 
 <body>
 <div class="container">
 
 <form action="http://www.fkit.org" class="form-horizontal">
 
 <div class="form-group">
 <label for="name" class="col-sm-2 control-label">用户名</label>
 <div class="col-sm-3">
 
 <input type="text" class="form-control" id="name" placeholder="用户名">
 </div>
 </div>
 <div class="form-group">
 <label for="passwd" class="col-sm-2 control-label">密码</label>
 <div class="col-sm-6">
 
 <input type="password" class="form-control" id="passwd" placeholder="密码">
 </div>
 </div>
 <div class="form-group">
 <label for="passwd" class="col-sm-2 control-label">电子邮件</label>
 <div class="col-sm-4">
 
 <input type="email" class="form-control" id="email" placeholder="电子邮件">
 </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>
 </div>
 <script type="text/javascript" src="../jquery-3.1.1.js"></script>
 <script type="text/javascript" src="../bootstrap/js/bootstrap.min.js"></script>
 </body>
 
 </html>
 
 | 
原文链接: 6.9.5 表单控件的大小