0

I'm working in bootstrap and looking to create a form that has 2 rows and a submit button. The first row should have 1 number field, where row 2 should have 3 number fields directly underneath the first row. Do I use the column and row class like below?

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />

<form role="form">
  <div class="row">
    <input type="number" class="col-xs-12">
  </div>
  <div class="row">
    <input type="number" class="col-xs-3">
    <input type="number" class="col-xs-3">
    <input type="number" class="col-xs-3">
  </div>
</form>

Any help is appreciated!

1
  • I tested, it's OK. What is your problem? Commented Jul 5, 2015 at 3:36

2 Answers 2

3

You are missing some important parts.

The column classes should be added to div not input.
Also the columns should be wrapped in a row div.
Bootstrap has 12 column grid, so the sum of your columns should be 12.
That's why i changed col-xs-3 to col-xs-4 (3 columns of size 4).
Also you should add the class form-control to the inputs in order to give them the proper styling.

Take a look at this code:

.my-margin {
    margin-bottom: 20px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<form role="form">
    <div class="container">
        <div class="row my-margin">
            <div class="col-xs-12">
                <input type="number" class="form-control">
            </div>
        </div>
        <div class="row">
            <div class="col-xs-4">
                <input type="number" class="form-control">
            </div>
            <div class="col-xs-4">
                <input type="number" class="form-control">
            </div>
            <div class="col-xs-4">
                <input type="number" class="form-control">
            </div>
        </div>
    </div>
</form>

Also i suggest you read this tutorial on the grid system in bootstrap.

Sign up to request clarification or add additional context in comments.

Comments

0

The inline form can be done with form-inline

Inline form

Add .form-inline to your form (which doesn't have to be a ) for left-aligned and inline-block controls.

The solution by wazaap is also good.

Bootstrap form-inline reference

.input-num {
    margin-bottom: 10px;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />

<div class="container">
<form role="form">
 <div class="row col-xs-12 input-num">
     <input type="number" class="col-xs-12" placeholder="Enter a number"/>
 </div>
  <div class="container">
    <div class="row form-inline grp-num">
        <input type="number" placeholder="Enter a number"/>
        <input type="number" placeholder="Enter a number"/>
        <input type="number" placeholder="Enter a number"/>
    </div>
 </div>
</form>
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.