温馨提示:本文翻译自stackoverflow.com,查看原文请点击:html - How to align labels with inputs using bootstrap?

html - 如何使用引导程序使标签与输入对齐?

发布于 2020-04-05 00:40:25

我正在尝试对齐此表格

在此处输入图片说明

我想得到这样的东西 在此处输入图片说明

总是将标签放到另一个位置..并且输入内容无法容纳...我该如何处理?

我正在使用此代码

<div class="form-group col-xs-3 col-md-4" >
        <label class="control-label col-md-4" >Rif: </label>
        <div class="col-md-8">
         <input type="text" name="rif" id="rif" class="form-control" />
        </div>
       </div>

       <div class="form-group col-xs-3 col-md-4">
        <label class="control-label col-md-4">Empresa: </label>
        <div class="col-md-8">
         <input type="text" name="razon_social" id="razon_social" class="form-control" />
        </div>
       </div>

       <div class="form-group col-xs-3 col-md-4">
        <label class="control-label col-md-4">Rif.Holding: </label>
        <div class="col-md-8">
        <select name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">
        <option value="1" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">Rif 1</option>
        <option value="2" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">Rif 2</option>
        <option value="3" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">Rif 3</option>
        <option value="4" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">Rif 4</option>
        <option value="5" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">Rif 5</option>
        </select>
        </div>
       </div>

        <div class="form-group col-xs-3 col-md-4">
        <label class="control-label col-md-4">Nom.Holding:</label>
        <div class="col-md-8">
        <select name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">
        <option value="1" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">NomHolding 1</option>
        <option value="2" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">NomHolding 2</option>
        <option value="3" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">NomHolding 3</option>
        <option value="4" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">NomHolding 4</option>
        <option value="5" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">NomHolding 5</option>
        </select>
        </div>
       </div>

       <div class="form-group col-xs-3 col-md-4">
        <label class="control-label col-md-4">PIN: </label>
        <div class="col-md-8">
        <select name="fk_pin_id" id="fk_pin_id" class="form-control">
        <option value="1" name="fk_pin_id" id="fk_pin_id" class="form-control">Pin 1</option>
        <option value="2" name="fk_pin_id" id="fk_pin_id" class="form-control">Pin 2</option>
        <option value="3" name="fk_pin_id" id="fk_pin_id" class="form-control">Pin 3</option>
        <option value="4" name="fk_pin_id" id="fk_pin_id" class="form-control">Pin 4</option>
        <option value="5" name="fk_pin_id" id="fk_pin_id" class="form-control">Pin 5</option>
        </select>
        </div>
       </div>

       <div class="form-group col-xs-3 col-md-4">
        <label class="control-label col-md-4">Cartera: </label>
        <div class="col-md-8">
        <select name="fk_cartera_id" id="fk_cartera_id" class="form-control">
        <option value="1" name="fk_cartera_id" id="fk_cartera_id" class="form-control">Cartera 1</option>
        <option value="2" name="fk_cartera_id" id="fk_cartera_id" class="form-control">Cartera 2</option>
        <option value="3" name="fk_cartera_id" id="fk_cartera_id" class="form-control">Cartera 3</option>
        <option value="4" name="fk_cartera_id" id="fk_cartera_id" class="form-control">Cartera 4</option>
        <option value="5" name="fk_cartera_id" id="fk_cartera_id" class="form-control">Cartera 5</option>
        </select>
        </div>
       </div>

如何在不丢失格式的情况下对齐项目?有人可以帮我吗?

查看更多

提问者
Oscar
被浏览
38
beanic 2020-02-01 00:29

在这里,您有与所寻找的相似的东西:

<form>
  <div class="form-row justify-content-between">
    <div class="form-group row col-md-4">
      <label class="col-sm-4 col-form-label">Rif: </label>
      <div class="col-sm-8">
        <input type="text" name="rif" id="rif" class="form-control" />
      </div>
    </div>

    <div class="form-group row col-md-8">
      <label class="col-sm-2 col-form-label">Empresa: </label>
      <div class="col-sm-10">
        <input type="text" name="razon_social" id="razon_social" class="form-control" />
      </div>
    </div>
  </div>

  <div class="form-row justify-content-between">
    <div class="form-group row col-md-4">
      <label class="col-sm-4 col-form-label">Rif.Holding: </label>
      <div class="col-sm-8">
        <select name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">
          <option value="1" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">Rif 1</option>
          <option value="2" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">Rif 2</option>
          <option value="3" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">Rif 3</option>
          <option value="4" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">Rif 4</option>
          <option value="5" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">Rif 5</option>
        </select>
      </div>
    </div>

    <div class="form-group row col-md-8">
      <label class="col-sm-2 col-form-label">Nom.Holding: </label>
      <div class="col-sm-10">
        <select name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">
          <option value="1" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">NomHolding 1</option>
          <option value="2" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">NomHolding 2</option>
          <option value="3" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">NomHolding 3</option>
          <option value="4" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">NomHolding 4</option>
          <option value="5" name="fk_empresaholding_id" id="fk_empresaholding_id" class="form-control">NomHolding 5</option>
        </select>
      </div>
    </div>
  </div>

  <div class="form-row justify-content-between">
    <div class="form-group row col-md-4">
      <label class="col-sm-4 col-form-label">PIN: </label>
      <div class="col-sm-8">
        <select name="fk_pin_id" id="fk_pin_id" class="form-control">
          <option value="1" name="fk_pin_id" id="fk_pin_id" class="form-control">Pin 1</option>
          <option value="2" name="fk_pin_id" id="fk_pin_id" class="form-control">Pin 2</option>
          <option value="3" name="fk_pin_id" id="fk_pin_id" class="form-control">Pin 3</option>
          <option value="4" name="fk_pin_id" id="fk_pin_id" class="form-control">Pin 4</option>
          <option value="5" name="fk_pin_id" id="fk_pin_id" class="form-control">Pin 5</option>
        </select>
      </div>
    </div>

    <div class="form-group row col-md-4">
      <label class="col-sm-4 col-form-label">Cartera: </label>
      <div class="col-sm-8">
        <select name="fk_cartera_id" id="fk_cartera_id" class="form-control">
          <option value="1" name="fk_cartera_id" id="fk_cartera_id" class="form-control">Cartera 1</option>
          <option value="2" name="fk_cartera_id" id="fk_cartera_id" class="form-control">Cartera 2</option>
          <option value="3" name="fk_cartera_id" id="fk_cartera_id" class="form-control">Cartera 3</option>
          <option value="4" name="fk_cartera_id" id="fk_cartera_id" class="form-control">Cartera 4</option>
          <option value="5" name="fk_cartera_id" id="fk_cartera_id" class="form-control">Cartera 5</option>
        </select>
      </div>
    </div>

    <div class="form-group row col-md-4">
      <label class="col-sm-4 col-form-label">Cartera: </label>
      <div class="col-sm-8">
        <select name="fk_cartera_id" id="fk_cartera_id" class="form-control">
          <option value="1" name="fk_cartera_id" id="fk_cartera_id" class="form-control">Cartera 1</option>
          <option value="2" name="fk_cartera_id" id="fk_cartera_id" class="form-control">Cartera 2</option>
          <option value="3" name="fk_cartera_id" id="fk_cartera_id" class="form-control">Cartera 3</option>
          <option value="4" name="fk_cartera_id" id="fk_cartera_id" class="form-control">Cartera 4</option>
          <option value="5" name="fk_cartera_id" id="fk_cartera_id" class="form-control">Cartera 5</option>
        </select>
      </div>
    </div>
  </div>
</form>