7

我试图在水平表单组类中显示三个小文本框元素。使用代码

<div class="form-group">
           <label class="col-lg-3 control-label input-sm">Date of Birth:</label>
           <div class="col-lg-4">
              <div class="row">
                 <div class="col-lg-4">
                  <input type="text" id="txt_month" name="txt_month" class="form-control input-sm"  placeholder="MM" required maxlength="2" data-validation-required-message="Month is required" >
                 </div>
                  <div class="col-lg-4">
                   <input type="text" id="txt_day" name="txt_day" class="form-control input-sm"  placeholder="DD" required maxlength="2" data-validation-required-message="Day is required" >
                 </div>
                  <div class="col-lg-4">
                   <input type="text" id="txt_year" name="txt_year" class="form-control input-sm"  placeholder="YY" required maxlength="4" data-validation-required-message="Year is required" >
                 </div>

              </div>

           <p class="help-block"></p>
           </div>
         </div>

结果:

在此处输入图像描述

有没有更好的方法来显示彼此靠近的多个文本框。表单中的其余元素水平显示。

更新#

在使用带有许多其他修改的内联表单类之后,我得到了正确的结果。这是更新的代码。

<div class="form-group">
           <label class="col-lg-3 control-label input-sm">Date of Birth:</label>
           <div class="col-lg-7">
              <div class="form-inline">
                      <div class="form-group ">
                         <div class="col-lg-3">
                        <label class="sronly" for="txt_month">Enter Month</label> 
                        <input type="text" id="txt_month" name="txt_month" class="form-control input-sm" style="width:60px"  placeholder="MM" required maxlength="2" data-validation-required-message="Month is required" >
                        </div>
                      </div>
                      <div class="form-group">
                          <div class="col-lg-3">
                         <label class="sronly" for="txt_day">Enter Day</label> 
                         <input type="text" id="txt_day" name="txt_day" class="form-control input-sm" style="width:60px"  placeholder="DD" required maxlength="2" data-validation-required-message="Day is required" >
                         </div>
                      </div>
                      <div class="form-group">
                        <div class="col-lg-3">
                          <label class="sronly" for="txt_year">Enter Year</label> 
                          <input type="text" id="txt_year" name="txt_year" class="form-control input-sm" style="width:60px"  placeholder="YY" required maxlength="4" data-validation-required-message="Year is required" >
                        </div>
                      </div>
                 </div>
           <p class="help-block"></p>
           </div>
         </div>

正确结果:

在此处输入图像描述

4

2 回答 2

12

这个答案真的帮助我用 BS3 制定了我的表格。

但是我希望它看起来像这样:

创建没有标签的内联表单

所以,我修改了上面的内容并将“sr-only”类添加到我想要隐藏的标签中(所以屏幕阅读器仍然会选择它们),并更改了 col 大小。

(注意:OP 使用 'sronly' 类而不是 'sr-only' 类,这对我不起作用)

<div class="form-group">
  <label class="col-lg-3 control-label ">City & County:</label>
  <div class="col-lg-9">
    <div class="form-inline">
      <div class="form-group ">
        <div class="col-lg-12">
          <label class="sr-only" for="city">City</label> 
          <input type="text" id="city" name="city" class="form-control " placeholder="E.g. Manchester" >
        </div>
      </div> 
      <div class="form-group ">
        <div class="col-lg-12">
          <label class="sr-only" for="county">County</label> 
          <input type="text" id="county" name="county" class="form-control " placeholder="E.g. Lancashire" >
        </div>
      </div>
    </div>
  </div>
</div>
于 2013-10-22T12:18:36.833 回答
3

是的,使用内联表单。检查他们的文档

于 2013-09-06T17:57:34.950 回答