html - Bootstrap 3.0 : How to have text and input

我目前正在将我的网站切换到 Bootstrap 3.0。我在表单输入和文本格式方面遇到问题。在 Bootstrap 2 中有效的在 Bootstrap 3 中无效。

如何在表单输入之前和之后在同一行获取文本?我已将其范围缩小到示例的 Bootstrap 3 版本中的“表单控制”类的问题。

我将如何在一行中获取所有文本和输入?我希望 bootstrap 3 示例看起来像 jsfiddle 中的 bootstrap 2 示例。

JS fiddle example

<div class="container ">
  <form>
      <h3> Format used to look like this in Bootstrap 2 </h3>
      <div class="row ">
          <label for="return1"><b>Return:</b></label>
          <input id="return1" name='return1' class=" input input-sm" style="width:150px"
                 type="text" value='8/28/2013'>
          <span id='return1' style='color:blue'> +/- 14 Days</span>
      </div>

       <br>   
       <br>   
           <h3> BootStrap 3 Version </h3>

      <div class="row">
          <label for="return2"><b>Return:</b></label>
          <input id="return2" name='return2' class="form-control input input-sm" style="width:150px"
                 type="text" value='8/28/2013'>
          <span id='return2' style='color:blue'> +/- 14 Days</span>
      </div>
  </form>

更新: 我将代码更改为有效但现在无法对齐的代码。有什么想法吗?

<div class="form-group">
<div class="row">
    <div class="col-xs-3">
        <label for="class_type"><h2><span class=" label label-primary">Class Type</span></h2></label>
    </div>
    <div class="col-xs-2">
        <select name="class_type" id="class_type" class="  form-control input-lg" style="width:200px" autocomplete="off">
            <option >Economy</option>
            <option >Premium Economy</option>
            <option >Club World</option>
            <option >First Class</option>
        </select>
    </div>
 </div>

最佳答案

直接来自文档 http://getbootstrap.com/css/#forms-horizontal .

通过添加 .form-horizontal 使用 Bootstrap 的预定义网格类在水平布局中对齐标签和表单控件组到表单(不一定是 <form> )。这样做会改变 .form-groups表现得像网格行,所以不需要 .row .

示例:

<form class="form-horizontal">
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Email</label>
    <div class="col-sm-10">
      <input type="email" class="form-control" id="inputEmail3" placeholder="Email">
    </div>
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Password</label>
    <div class="col-sm-10">
      <input type="password" class="form-control" id="inputPassword3" placeholder="Password">
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <div class="checkbox">
        <label>
          <input type="checkbox"> Remember me
        </label>
      </div>
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-default">Sign in</button>
    </div>
  </div>
</form>

关于html - Bootstrap 3.0 : How to have text and input on same line?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18499041/

相关文章:

java - 生成用空格填充的固定长度字符串

python - 轻松漂亮地打印花车?

java - netbeans 中的代码清理

python - 使用标准 json 模块格式化 float

string - 如何将 Int 转换为给定长度的字符串,前导零对齐?

r - 如何打印(到纸上)格式良好的数据框

javascript - 在jQuery中将逗号添加到数字

c# - 在 C# 中的字符串中找到 {0} 是什么意思?

Excel CSV - 数字单元格格式

java - Intellij 代码格式化,Java 新行注解