通过添加.row类 ,并使用.col-- 等栅格组件来指定标签的宽度,可建立水平表单。
确保添加.col-form-label到上,以便垂直居中。
使用class="col-form-label"之前
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>表单【上】</title>
<!-- 引入Bootstrap CSS -->
<link rel="stylesheet" href="../css/bootstrap.css">
<!-- 移动设备优先 -->
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<style>
body {
margin: 20px;
}
</style>
</head>
<body>
<from action="">
<div class="form-group row">
<label for="email" class="col-3">请输入邮箱地址:</label>
<input type="text" id="email" class="col-9 form-control-plaintext" value="langwaishige@hotmail.com" readonly="readonly">
</div>
<div class="form-group">
<label for="password">请输入密码:</label>
<input type="password" id="password" class="form-control form-control-sm">
</div>
<div class="form-group">
<input type="checkbox" id="check" class="form-control-input">
<label for="check">是否保存</label>
</div>
<div class="form-group">
<label for="city">请选择您去过的城市:</label>
<select multiple="multiple" name="" id="city" class="form-control">
<option value="1">北京</option>
<option value="2">上海</option>
<option value="3">深圳</option>
</select>
</div>
<div class="form-group">
<label for="info">详情:</label>
<textarea name="" id="info" cols="30" rows="10" class="form-control"></textarea>
</div>
<div class="form-group">
<label for="file">请输入密码:</label>
<input type="file" id="file" class="form-control-input">
</div>
</from>
<!-- 引入jQuery文件 -->
<script src="../js/jquery-3.3.1.js"></script>
<script src="../js/bootstrap.js"></script>
</body>
</html>
使用class="col-form-label"之后
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>表单【上】</title>
<!-- 引入Bootstrap CSS -->
<link rel="stylesheet" href="../css/bootstrap.css">
<!-- 移动设备优先 -->
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<style>
body {
margin: 20px;
}
</style>
</head>
<body>
<from action="">
<div class="form-group row">
<label for="email" class="col-3 col-form-label">请输入邮箱地址:</label>
<input type="text" id="email" class="col-9 form-control-plaintext" value="langwaishige@hotmail.com" readonly="readonly">
</div>
<div class="form-group">
<label for="password">请输入密码:</label>
<input type="password" id="password" class="form-control form-control-sm">
</div>
<div class="form-group">
<input type="checkbox" id="check" class="form-control-input">
<label for="check">是否保存</label>
</div>
<div class="form-group">
<label for="city">请选择您去过的城市:</label>
<select multiple="multiple" name="" id="city" class="form-control">
<option value="1">北京</option>
<option value="2">上海</option>
<option value="3">深圳</option>
</select>
</div>
<div class="form-group">
<label for="info">详情:</label>
<textarea name="" id="info" cols="30" rows="10" class="form-control"></textarea>
</div>
<div class="form-group">
<label for="file">请输入密码:</label>
<input type="file" id="file" class="form-control-input">
</div>
</from>
<!-- 引入jQuery文件 -->
<script src="../js/jquery-3.3.1.js"></script>
<script src="../js/bootstrap.js"></script>
</body>
</html>