将标签放在输入表单旁边

时间:2014-04-12 18:45:33

标签: css forms css3 twitter-bootstrap blade

我正在使用bootstrap和laravel(刀片)作为后端,并且无法将我的代码上传到jdfiddle中以显示。但问题是标签远离输入框,是否可以将它放在中间?

enter image description here

<div class="row">
         {{ Form::open(array('url' => 'bassengweb/insertHV', 'method' => 'POST')) }}
                <div class="col-md-6">
                    <div class="form-group">


    <label class="col-md-6 col-lg-6 control-label">Dato: </label>
                    <div class="col-md-6 col-lg-6">
                      {{ Form::text('Date', $date, array('class' => 'form-control')) }}
                    </div>
                </div>
            </div>

    <div class="col-md-6 text-left-imp"> 


                <div class="form-group">
                    <label class="col-md-6 col-lg-6 control-label">Tid: </label>
                    <div class="col-md-6 col-lg-6">
                      {{ Form::text('Time', $time, array('class' => 'form-control')) }}
                    </div>
                </div>


    </div>
    </div>

1 个答案:

答案 0 :(得分:6)

您的标签上有col-md-6类,这会使它们相当宽。我尝试以下任何一种方法:

  • 使用较小的标签栏,可能是col-md-3
  • 在标签内使用text-align: right将其推送到输入旁边
  • 尝试使用form-inlineform-horizontal,看看它是否能满足您的需求

这是form-horizontalAPI sample中使用的标记(注意元素的排列方式):

<form class="form-horizontal" role="form">
  <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>