Align inputs HTML form

1

Hello, I have a problem with the form and I want to align the inputs to the right.

nombre    : input
apellidos : input input

I'm currently looking like this:

nombre
input
apellidos 
input 
input

link thank you! :)

    
asked by kaiCo 13.09.2017 в 12:15
source

4 answers

0

It's very simple, I give you an example, you must put each field in a different column.

In the example I put a .col-sm-2 for label , and .col-sm-5 for form fields; all within a .form-group

Do not forget to run and expand to see the example in full screen. Tell me if there is something you do not understand.

/* Link boostrap */
@import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css');
<form class="form-horizontal">
  <div class="form-group">
    <label for="input-nombre" class="col-sm-2 control-label">Nombre</label>
    <div class="col-sm-5">
      <input type="text" class="form-control" id="input-nombre" placeholder="Nombre">
    </div>
  </div>
  <div class="form-group">
    <label for="input-apellido" class="col-sm-2 control-label">Apellidos</label>
    <div class="col-sm-5">
      <input type="text" class="form-control" id="input-apellido-1" placeholder="Apellido Uno">
    </div>
    <div class="col-sm-5">
      <input type="text" class="form-control" id="input-apellido-2" placeholder="Apellido Dos">
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-success">Enviar formulario</button>
    </div>
  </div>
</form>

Also seeing your code:

  • you are missing the class="form-control" bootstrap for each field form
  • you have to use .form-group for each field with its label
answered by 13.09.2017 / 15:40
source
1

This could be worth you (I have not used bootstrap): link

    
answered by 13.09.2017 в 12:31
0

Try doing it following this example:

<div class="form-group">
    <div class="row">
        <div class="col-lg-offset-1 col-lg-2">
            <label for="nombre">Nombre</label>
        </div>
        <div class="col-lg-8">
            <input type="text" class="form-control" name="nombre">
        </div>
    </div>
</div>

Good luck!

    
answered by 13.09.2017 в 12:24
0

Try this:

    <form action="" class="form-inline">
        <div class="form-group">
           <label for="nombre" class="control-label col-sm-3">Nombre</label>
              <div class="col-sm-9">
                 <input type="text" id="nombre" class="form-control">
              </div>
        </div>
    </form>
    
answered by 13.09.2017 в 17:23