使用 Bootstrap 让表单控件的标签和组在水平布局对齐


使用 Bootstrap 中的 .form-horizontal 类,即可让表单控件的标签和组在水平布局对齐。

你可以尝试运行以下代码来实现 .form-horizontal

示例

现场演示

<!DOCTYPE html>
<html>
   <head>
      <title>Bootstrap Example</title>
      <link href = "/bootstrap/css/bootstrap.min.css" rel = "stylesheet">
      <script src = "/scripts/jquery.min.js"></script>
      <script src = "/bootstrap/js/bootstrap.min.js"></script>
   </head>
   <body>
      <form class = "form-horizontal" role = "form">
         <div class = "form-group">
            <label class = "sr-only" for = "name">Name</label>
            <input type = "text" class = "form-control" id = "name" placeholder = "Enter Name">
         </div>
         <div class = "form-group">
            <label class = "sr-only" for = "name">Name</label>
            <input type = "number" class = "form-control" id = "name" placeholder = "Enter Age">
         </div>
         <button type = "submit" class = "btn btn-primary">Submit</button>
      </form>
   </body>
</html>

更新于: 2020 年 6 月 12 日

2K+ 次浏览

开启你的 职业生涯

完成课程,获得认证

开始学习
广告
© . All rights reserved.