Display two fields side by side in a Bootstrap Form

前端 未结 8 925
执笔经年
执笔经年 2020-12-23 12:52

I am trying to display a year range input on a form that has a 2 textboxes. One for the min and one for the max and are separated by a dash.

I want this all on the

相关标签:
8条回答
  • 2020-12-23 13:35

    @KyleMit's answer on Bootstrap 4 has changed a little

    <div class="input-group">
        <input type="text" class="form-control">
        <div class="input-group-prepend">
            <span class="input-group-text">-</span>
        </div>
        <input type="text" class="form-control">
    </div>
    
    0 讨论(0)
  • 2020-12-23 13:35

    Just put two inputs inside a div with class form-group and set display flex on the div style

    <form method="post">
    <div class="form-group" style="display: flex;"><input type="text" class="form-control" name="nome" placeholder="Nome e sobrenome" style="margin-right: 4px;" /><input type="text" class="form-control" style="margin-left: 4px;" name="cpf" placeholder="CPF" /></div>
    <div class="form-group" style="display: flex;"><input type="email" class="form-control" name="email" placeholder="Email" style="margin-right: 4px;" /><input type="tel" class="form-control" style="margin-left: 4px;" name="telephone" placeholder="Telefone" /></div>
    <div class="form-group"><input type="password" class="form-control" name="password" placeholder="Password" /></div>
    <div class="form-group"><input type="password" class="form-control" name="password-repeat" placeholder="Password (repeat)" /></div>
    <div class="form-group">
        <div class="form-check"><label class="form-check-label"><input type="checkbox" class="form-check-input" />I agree to the license terms.</label></div>
    </div>
    <div class="form-group"><button class="btn btn-primary btn-block" type="submit">Sign Up</button></div><a class="already" href="#">You already have an account? Login here.</a></form>
    
    0 讨论(0)
  • 2020-12-23 13:35

    @KyleMit answer is one way to solve this, however we may chose to avoid the undivided input fields acheived by input-group class. A better way to do this is by using form-group and row classes on a parent div and use input elements with grid-system classes provided by bootstrap.

    <div class="form-group row">
        <input class="form-control col-md-6" type="text">
        <input class="form-control col-md-6" type="text">
    </div>
    
    0 讨论(0)
  • 2020-12-23 13:42

    did you check boostrap website? search for "forms"

    <div class="form-row">
    <div class="col">
      <input type="text" class="form-control" placeholder="First name">
    </div>
    <div class="col">
      <input type="text" class="form-control" placeholder="Last name">
    </div>
    
    0 讨论(0)
  • 2020-12-23 13:45

    Bootstrap 3.3.7:

    Use form-inline.

    It only works on screen resolutions greater than 768px though. To test the snippet below make sure to click the "Expand snippet" link to get a wider viewing area.

            <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
            <form class="form-inline">
                <input type="text" class="form-control"/>-<input type="text" class="form-control"/>
            </form>

    Reference: https://getbootstrap.com/docs/3.3/css/#forms-inline

    0 讨论(0)
  • 2020-12-23 13:46

    The problem is that .form-control class renders like a DIV element which according to the normal-flow-of-the-page renders on a new line.

    One way of fixing issues like this is to use display:inline property. So, create a custom CSS class with display:inline and attach it to your component with a .form-control class. You have to have a width for your component as well.

    There are other ways of handling this issue (like arranging your form-control components inside any of the .col classes), but the easiest way is to just make your .form-control an inline element (the way a span would render)

    0 讨论(0)
提交回复
热议问题